in reply to Re: for loop to get the 3rd index
in thread for loop to get the 3rd index
There are some problems with your solution.
1. To get your match into $1, it should be m/(matchingStuff)/. That is, there needs to be parens.
2. Your 'if' statement should be if ($match_count == 3). This is a numerical comparison.
Try this:
1. To get your match into $1, it should be m/(matchingStuff)/. That is, there needs to be parens.
2. Your 'if' statement should be if ($match_count == 3). This is a numerical comparison.
Try this:
my @matches; open (F,"files.txt") || die ("Couldn't open file: $!\n"); while(<F>) { chomp; if (/matchingstffHere/) { push(@matches, $_); } } close(F); if (scalar(@matches) >= 3) { print "Needed = $matches[2].\n"; }
|
---|
In Section
Seekers of Perl Wisdom