in reply to next in while loop not honored

Using the $. special variable is the easiest solution. And it is fine here, since you are planning to print only a few lines. But if the file you are reading is huge and just want to skip the first line, then it is faster to avoid making the test for every single line you are reading by removing the header line before entering the loop:
# ... my $useless_line = <$info>; # reads the first line and throws it away while( my $line = <$info>) { print $line; last if $. >= $maxline; print "$. \n"; }

Replies are listed 'Best First'.
Re^2: next in while loop not honored
by GrandFather (Saint) on Nov 05, 2014 at 20:27 UTC

    The trivial time that may be saved due to removing a simple test is completely irrelevant. However there is a generally big gain in clarity by simplifying code. In that vein, my $useless_line = <$info>; should simply be <$info>; which is much better at conveying the idea that we really don't want to use the contents of the line just read.

    Perl is the programming world's equivalent of English
      I found time not so trivial when reading several files with 300 M + lines. It also makes the loop cleaner by removing from it things that don't need to be in it. It also make the algorithm slightly simpler when reading a sorted file to remove duplicates or reading in parallel two (or more) files sorted according to the same key to compare data.

      As for the my $useless_line = <$info>;, I would probably not really code it that way, but I thought giving such a name would make it more self-explanatory to the OP, you seem to disagree, maybe I was wrong, I don't know.