in reply to peeling the top 10 lines from a file

See above for fixing a syntax error. As for your empty newlines, it is because $_ includes the newline (i'm assuming $/ is \n) from the input file, so that is getting printed along with the one you put in your print statement.

Also take a look at $. in the perlvar man page, which may be of interest to you. It's the current input record number, which you can use instead of having $counter (same functionality--just eliminates an extra variable).
while( <> ){ print; # bail if past 10 lines # or if we hit a blank line last if $. >= 10 || $_ eq "\n"; }

Replies are listed 'Best First'.
Re^2: peeling the top 10 lines from a file
by holli (Abbot) on May 16, 2005 at 15:39 UTC
    holli slaps his forehead

    I always forget about $.. This must be one of my blind spots.


    holli, /regexed monk/
      The only advice I can give you is in my sig.

      The Eightfold Path: 'use warnings;', 'use strict;', 'use diagnostics;', perltidy, CGI or CGI::Simple, try the CPAN first, big modules and small scripts, test first.

Re^2: peeling the top 10 lines from a file
by Nkuvu (Priest) on May 16, 2005 at 18:26 UTC
    Why are you bailing on blank lines? That wasn't specified in the OP, unless I'm missing something. Which is entirely possible, given my current caffeine level (low).
      I wasn't at first, then I re-read OP which said "looking for an empty line at the top of a file", and made me re-consider and add it in. I still don't know if bailing on blank lines is what the OP really needs/or wants, but from that quote i think it's possible so i figured i'd just throw it in and comment it and let OP go from there...

      Maybe i read too far into it -- none of the other responsers intrepeted it that way, but maybe they were going just off of the sample code...