Two thoughts here:

1) The $. Variable has the line number of the file you are iterating
through, so you could use that combined with pos()

2) You could also try something like this:

while(<INFILE>){
   if($_ =~ /.{20}$pattern.{20}/){
      push(@found,$1);
   }
}






-----Original Message-----
From: Tim & Kylie Duke [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 13, 2004 12:17 AM
To: Beginners perl
Subject: recording the position of m// searches

-------------<snip>----------------

So I am thinking, use m//g to search, then push the found locations onto
a list, then come back, printing out parts of the text file based on the
search positions in the list, and use a context of 20 characters on
either side.

The pos() function within a m//g loop seems to return the position
within the line, not the position within the file.  Is there a different
function to return the absolute position in the file, which I could then
use later on as a basis for (very roughly)
    for each sort(@found_locations)
         print text from $position - 20 to $position +20

-------------<snip>-----------------

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to