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/


Reply via email to