Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: how to find the length of any line of file -- oneliner

by Discipulus (Canon)
on Nov 23, 2017 at 08:52 UTC ( [id://1204116]=note: print w/replies, xml ) Need Help??


in reply to Re: how to find the length of any line of file
in thread how to find the length of any line of file

He! no need of BEGIN block nor say and chomp

perl -lne  "print length and exit if $. == 4"

the above will work with data passed via pipe and also with a filename passed as argument.

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: how to find the length of any line of file -- oneliner
by Laurent_R (Canon) on Nov 23, 2017 at 10:51 UTC
    Yes, Discipulus, no need for a begin block because you're hard coding the line number, whereas I wanted to pass it as an argument to the script and therefore needed to retrieve it (only once). Now, of course, for a one-liner, you might as well hard code the line number, it doesn't make a big difference.
      Hello Laurent_R, curiously enough (for me!)

       perl -lne  "print length  and exit if $. == $ARGV[0]"  datatest.txt 4

      does not complains about: Can't open 4: No such file or directory at.. and works even without the BEGIN block

      It just runs ok with both passed as arguments, not with the data passed via pipe though.

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

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

    No recent polls found