in reply to Count number of lines in a text file

What about this oft-quoted golf shot?
perl -pe '}{$_=$.' filename

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: Count number of lines in a text file
by ambrus (Abbot) on Mar 24, 2006 at 10:29 UTC
    Very tricky. So because of the }, the continue { print $_; } block is no longer attached to the loop, but to the {$_=$.} bare block. I never knew this trick with -p. (I knew about -ne '...}{...' but not what it did with -p.)
      Yes. But -p and -n only differ by the continue/print. Compare -p:
      > perl -MO=Deparse -pe"#stuff#" LINE: while (defined($_ = <ARGV>)) { (); } continue { print $_; }
      to -n:
      > perl -MO=Deparse -ne"#stuff#" LINE: while (defined($_ = <ARGV>)) { (); }

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of