# adds line #'s before every line that
# match the expression at the command line,
# putting parens around the matches
#
$file = 'stam.txt';
open (TEXT, $file);
my $linenum = "000";
while ($line = <TEXT>){
if($line =~/($ARGV[0])/g){
$line =~ s/$1/($ARGV[0])/g;
$linenum++;
print "$linenum "."$line";
}
else{
print " $line";
}
}
In the substitution, I get an error ("use of uninitialized value"
when I try to use $1 in place of $ARGV[0]. I have tried using braces around the "1", or using "\1" (without the quotes), but I get the same message.
# match the expression at the command line,
# putting parens around the matches
#
$file = 'stam.txt';
open (TEXT, $file);
my $linenum = "000";
while ($line = <TEXT>){
if($line =~/($ARGV[0])/g){
$line =~ s/$1/($ARGV[0])/g;
$linenum++;
print "$linenum "."$line";
}
else{
print " $line";
}
}
In the substitution, I get an error ("use of uninitialized value"