Implement a program that processes an input file by changing every occurrence of an old string into a new string. (The usage is: chstr file oldstring newstring, chstr is your program name, file, oldstring and newstring are parameters specified by user.)
if( @ARGV < 2)
{
print "usage: ReplaceString.pl filename OldString NewString\n";
print " example: perl ReplaceString.pl intelliquest.txt ";
print "IntelliQuest Kantar > kantar.txt\n";
exit 0;
}
$OldString = $ARGV[1];
$NewString = $ARGV[2];
open(MYFILE,$ARGV[0]) || die "Cannot open file \"$ARGV[0]\"";
while($line = <MYFILE>)
{
$line =~ s/$OldString/$NewString/g;
print STDOUT $line;
}
really not sure what is wrong here, I try and run
jd@jd-laptop:~/Desktop$ perl HW1-2.pl text.txt if the
To replace if with the and i get...
syntax error at HW1-2.pl line 11, near "<"
syntax error at HW1-2.pl line 11, near ">"
syntax error at HW1-2.pl line 15, near "}"
Execution of HW1-2.pl aborted due to compilation errors.
Do i need the < and >? I'm really new to Perl
Thanks in advance