K
Kelly
I want to search for a letter and replace it but when I add the > to the
file name it acts up. When I take it out it works but obviously doesn't
alter the file only prints it altered. Can anyone tell me why??
use strict;
my $content;
## Prompt user for file #############
print "Enter the name of the file you would like to change...\n";
chomp (my $file=<STDIN>);
open (INFILE,">$file" || die "Cannot open $file");
## Prompt for old letter#############
print "Enter the letter you would like to replace...\n";
chomp(my $old=<>);
## Prompt for new letter ############
print "Enter the letter you would like to replace $old with...\n";
chomp(my $new=<>);
## Replace letters #
while($file=<INFILE>){
$content=$content . $file;
}
$content =~ s /$old/$new/sgi;
close INFILE;
print $content."\n";
print "Press ENTER to quit";
chomp ($file=<STDIN>);
file name it acts up. When I take it out it works but obviously doesn't
alter the file only prints it altered. Can anyone tell me why??
use strict;
my $content;
## Prompt user for file #############
print "Enter the name of the file you would like to change...\n";
chomp (my $file=<STDIN>);
open (INFILE,">$file" || die "Cannot open $file");
## Prompt for old letter#############
print "Enter the letter you would like to replace...\n";
chomp(my $old=<>);
## Prompt for new letter ############
print "Enter the letter you would like to replace $old with...\n";
chomp(my $new=<>);
## Replace letters #
while($file=<INFILE>){
$content=$content . $file;
}
$content =~ s /$old/$new/sgi;
close INFILE;
print $content."\n";
print "Press ENTER to quit";
chomp ($file=<STDIN>);