On Wed, May 01, 2002 at 01:52:35PM -0500, Frank Newland wrote:
> Ladies and Gentlemen:
>
> I'm using a while loop to search for specific record.
A record is a single line in your file?
> If I find the record, then I need to report that record and the trailer
> record.
Sorry, insufficient english on my side. Is the 'trailer' record the one
you read before the current record?
> I'm not slurping the file into memory so I can't use $openfile[$#openfile]
> approach.
Not necessary.
Use a 2 element circlular list fifo to store the elements while reading.
-- untested --
my $current = 0;
my @stash = (undef, undef);
while () {
chomp; # not necessary...
$stash[$current] = $_; # store for later use
if (/YOUR PATTERN/) {
print "Match is '$_'\n";
print "Prev is '" . $stash[1 - $current] . "'\n";
}
$current = 1 - $current;# toggle for next run
}
-- untested --
The '$current = 1 - $current' is commonly used in games for selecting
sprite coordinates on double-buffered screens :-)
--
If we fail, we will lose the war.
Michael Lamertz| +49 221 445420 / +49 171 6900 310
Nordstr. 49| [EMAIL PROTECTED]
50733 Cologne | http://www.lamertz.net
Germany| http://www.perl-ronin.de
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]