http://qs321.pair.com?node_id=748859


in reply to Re^2: Hmmm: while(), file handle and $_ gotcha
in thread Hmmm: while(), file handle and $_ gotcha

or
for my $cnt (0 .. 3) { print scalar(<DATA>); }

Replies are listed 'Best First'.
Re^4: Hmmm: while(), file handle and $_ gotcha
by hbm (Hermit) on Mar 06, 2009 at 14:12 UTC

    Cool! And then perhaps:

    while (<DATA>) { if ($. % 10 == 1) { print; print scalar(<DATA>) for(0..3); } }
      Since we want to print the first 5 lines of each group of 10,
      while (<DATA>) { print if ($. - 1) % 10 < 5; }