Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by 2teez (Priest)
on Oct 30, 2013 at 13:24 UTC ( #1060373=note: print w/ replies, xml ) Need Help??


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

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


Comment on Re^3: Break one liner command line script after first match
Select or Download Code
Re^4: Break one liner command line script after first match
by McA (Curate) on Oct 30, 2013 at 13:32 UTC

    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://1060373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-08-30 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls