in reply to newbie questions on array access and control loops
my @filelines = <FILE>; #Read the entire file into an array my $whichline; #Declare a variable to hold the line number for(my $i = 0; $i = $#filelines; $i++){ #Go through the entire array +untill you find it or run out of lines if($filelines[$i] =~ m/TEXTTOMATCH/o){ #Attempt to match, use compi +le-once $whichline = $i; #If match, remember the line + and leave the loop. last; } }
Once you have the line with that, you can use splice() to remove the line if you wish, or do something else to it...my @filelines = <FILE>; #Read the entire file into an array my @whichline; #Declare a variable to hold the line number for(my $i = 0; $i = $#filelines; $i++){ #Go through the entire array +untill you find it or run out of lines if($filelines[$i] =~ m/TEXTTOMATCH/o){ #Attempt to match, use compi +le-once push(@whichline,$i); #If match, add to the list of current match +es } } #Now you know what lines had TEXTTOMATCH in them
|
|---|