in reply to Re^2: Parsing text file question
in thread Parsing text file question

Thanks all for replies. Neniro. It looks like your code suggestion will put all lines except those starting with "fail" to @lines array. What I need is to take out is the 1 line exactly above the fail. Thanks again.

Replies are listed 'Best First'.
Re^4: Parsing text file question
by neniro (Priest) on Jun 28, 2004 at 09:06 UTC
    Sorry, I missed the task. The following should work:
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; chomp (my @lines = <>); for (0..$#lines) { $lines[$_-1] = undef if ($lines[$_] =~ /fail/)}; @lines = grep (defined, @lines); print Dumper \@lines;