in reply to Issue with unless statement with two conditions acting on two lines

use strict; use warnings; my $saw_an_s = 0; while (my $current_line = <DATA>) { next if ($saw_an_s and $current_line =~ /^s/); $saw_an_s = $current_line =~ /^s/ ? 1 : 0; print $current_line; } __DATA__ s 1 s 2 s 3 a a foo s 4 s 5 s 6 a bar

Just keep a flag rather than store the whole of the previous line each time - much simpler (to my mind). HTH.

  • Comment on Re: Issue with unless statement with two conditions acting on two lines
  • Download Code

Replies are listed 'Best First'.
Re^2: Issue with unless statement with two conditions acting on two lines
by rjc33 (Sexton) on Jan 08, 2016 at 16:07 UTC
    Thanks for the suggestion, I'll try this in the future!

      Note that hippo's approach above also prints the first line without further effort.


      Give a man a fish:  <%-{-{-{-<