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

Hi Sören,
you can do this in one step:
chomp (my @lines = grep (!/^fail/, <>));
neniro

Replies are listed 'Best First'.
Re^3: Parsing text file question
by sashac88 (Beadle) on Jun 28, 2004 at 08:58 UTC
    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.
      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;