Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Length

by Juerd (Abbot)
on Mar 14, 2002 at 07:46 UTC ( #151621=sourcecode: print w/ replies, xml ) Need Help??

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'

Comment on Length
Download Code
(jeffa) Re: Length
by jeffa (Chancellor) 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
      

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://151621]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (15)
As of 2015-05-04 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (106 votes), past polls