Hi Mark

        You have opened OUTFILE (OUTFILE, "<$output" ) in read mode . To
write to this file you need to open in write mode (">$output").

Sunita

-----Original Message-----
From: mark baumeister [mailto:mlfmp...@gmail.com] 
Sent: Tuesday, April 12, 2011 6:18 AM
To: beginners@perl.org
Subject: writing to output using filehandles

Hi I am having trouble with my search and replace code in the program
below.
I can sucessfully copy the input file to the output file but
my search and replace is not working.  Any hints on what I am doing
wrong?
Thanks,
M


#!/usr/bin/perl -w
use strict;

my $input;
my $output;
my $search;
my $replace;

print "enter an input file name:\n";
$input = <STDIN>;
chomp($input);

print "enter an output file name:\n";
$output = <STDIN>;
chomp($output);


print "enter a search pattern:\n";
$search = <STDIN>;
chomp($search);

print "enter a replacement string:\n";
$replace = <STDIN>;
chomp($replace);

open INFILE, "<$input" or die "Can't open $input ($!)";
open OUTFILE, "<$output" or die "Can't open $output ($!)";

while (<INFILE>) {
s/$search/$replace/g;
print OUTFILE $_;
}


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to