I am trying to run this program that I wrote and I keep getting an error message that states the following
Use of uninitialized value $ARGV[1] in substitution iterator at ./replaceName.pl line 22.
since the value is the name that is passed from the command line and is the second argument I am not sure what is wrong.
#!/usr/bin/env perl
use warnings;
@FILES = glob("*.txt");
foreach my $file(@FILES){
if( !defined($ARGV[2]) ){
$outfile = "$file.modified.txt";
}
else {
$outfile = $ARGV[2];
}
open FILE, "< $file" or die("File not found");
@lines = <FILE>;
close FILE;
open OUT, ">", $outfile;
foreach my $line (@lines) {
$line =~ s/YourName/$ARGV[1]/gi;
print OUT $line;
}
close OUT;
}