in reply to grabbing previous line in a log

Here's a way to do it using Tie::File, which also gives you the option of grabbing the previous n lines, not just the line immediately previous (maybe more useful if you need context in a log file.)

#! /usr/bin/perl use strict ; use warnings ; $|++ ; use Tie::File ; tie my @file, 'Tie::File', 'test_h.dat' or die "Can't tie file: $!" ; my $backtrack_lines = 1 ; my $match = '' ; for my $i ( 0 .. $#file ) { if ( $file[$i] =~ /baz/ ) { $match = join "\n", @file[ ( $i - $backtrack_lines ) .. $i ] ; } } print $match ; __END__

_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche