Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Break one liner command line script after first match

by McA (Curate)
on Oct 30, 2013 at 13:01 UTC ( #1060367=note: print w/ replies, xml ) Need Help??


in reply to Re: Break one liner command line script after first match
in thread Break one liner command line script after first match

Hi,

as you showed it with your solution: Be aware of the subtle difference between:

perl -ne'/(data)/ && print $1 and last' file.txt perl -ne'/(data)/ && print $1 && last' file.txt

That may bite someone (by the way: I was bitten ;-) )

McA


Comment on Re^2: Break one liner command line script after first match
Download Code
Re^3: Break one liner command line script after first match
by 2teez (Priest) on Oct 30, 2013 at 13:24 UTC

    Hi,
    Be aware of the subtle difference between:

    perl -ne'/(data)/ && print $1 and last' file.txt perl -ne'/(data)/ && print $1 && last' file.txt
    Of course, I saw the subtle difference, and how you used
    .. print ($1) ...

    the parentheses which is effectively the same thing if "and" is used instead of "&&"
    check this:

    Using
    perl -MO=Deparse -ne'/(data)/ && print $1 && last' file.txt
    you gets:
    LINE: while (defined($_ = <ARGV>)) { print $1 && last if /(data)/; }
    but using
    perl -MO=Deparse -ne'/(data)/ && print ($1) && last' file.txt
    gives:
    LINE: while (defined($_ = <ARGV>)) { last if /(data)/ and print $1; }
    Which is same as this:
    perl -MO=Deparse -ne'/(data)/ && print $1 and last' file.txt
    LINE: while (defined($_ = <ARGV>)) { last if /(data)/ and print $1; }

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

      I was sure that you know the difference. ;)

      I just wanted to point it out for the interested readers. And in the result we get just much more interesting stuff from you. ++ for that.

      Thank you.

      Best regards
      McA

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (17)
As of 2014-10-30 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls