in reply to Read n lines from the top of a text file

perl -pe "$.<11||last" test.txt

Replies are listed 'Best First'.
Re: Re: Read n lines from the top of a text file
by robin (Chaplain) on Dec 23, 2001 at 18:38 UTC
    This (reading 10 lines from the top of a text file) was the first hole in the recent fwp golf competition. Here's a summary of the solutions.

    The cleverest answer was by Piers Cawley:

    #!/usr/bin/perl -p 11..&
    Bonus points if you can figure out how it works :-)

      Hmm that is really obscure.

      C:\>perl -pe "11..&" test.pl 1 2 3 4 5 6 7 8 9 10 Undefined subroutine &main::; called, <> line 11. C:\>

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print