Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Length

by Juerd (Abbot)
on Mar 14, 2002 at 07:46 UTC ( [id://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'
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
      

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-19 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found