http://www.perlmonks.org?node_id=151621
Category: Utility Scripts
Author/Contact Info Juerd
Description: This code is very simple, and I think every experienced Perl coder can think of it. However, I use this twice a day, so it's useful to me. It might help out others, or at least make some of you toss away those old while(1) { print length(<>) - 1, "\n" } scripts that some people have.
perl -ple'$_=length'
Replies are listed 'Best First'.
(jeffa) Re: Length
by jeffa (Bishop) on Mar 14, 2002 at 14:02 UTC
    Very nice!

    I thought of a good use for it - checking for spaces on (what should be) blank lines in POD. It inspired me to alter it to:

    perl -nle' print $. if length==1'
    Thanks Juerd!

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      Great idea, but the thing that bites me most is having indents in pieces of code in POD. Between paragraphs, lines should be empty, even when dealing with code. So I changed it to:

      perl -nle'/^\s+$/&&print$.'

      U28geW91IGNhbiBhbGwgcm90MTMgY
      W5kIHBhY2soKS4gQnV0IGRvIHlvdS
      ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
      geW91IHNlZSBpdD8gIC0tIEp1ZXJk