Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: if modifier of a print statement

by davorg (Chancellor)
on Jun 30, 2009 at 10:51 UTC ( [id://775975]=note: print w/replies, xml ) Need Help??


in reply to if modifier of a print statement

I strongly suspect you're being bitten by operator precedence.

print $_ . "\n" and next if /no_proc/;
--

See the Copyright notice on my home node.

Perl training courses

Replies are listed 'Best First'.
Re^2: if modifier of a print statement
by tprocter (Sexton) on Jun 30, 2009 at 11:14 UTC
    davorg is right. This is a precedence issue.

    using 'and' instead of '&&' lowers the operator precedence.

    The first one is interpreted as:
    print $_ . ("\n" && next) if /no_proc/;

    The fixed one is intepreted as:
    (print $_ . "\n") and next if /no_proc/;

    Note that the brackets include the print statement, not just the parameters.
      The first one is interpreted as:
      print $_ . ("\n" && next) if /no_proc/;

      The  . operator has higher precedence than the  && operator so it is actually interpreted as:

      $ perl -MO=Deparse,-p -e' print $_ . "\n" && next if /no_proc/; ' (/no_proc/ and print((($_ . "\n") && next))); -e syntax OK

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-16 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found