Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: True or False? A Quick Reference Guide

by Zaxo (Archbishop)
on Sep 29, 2005 at 05:32 UTC ( #495986=note: print w/ replies, xml ) Need Help??


in reply to True or False? A Quick Reference Guide

bobf++, well done.

There is another logical operator; I like to regard the sequence operator, scalar comma, as the unconditional logical operator. The right hand argument is evaluated regardless of the truth of the already-evaluated left, and the last evaluated value is returned. Naturally, this has more use in shoehorning several evaluations into a single expression than in pure logic. It's often useful that way in the body of modifier statements like s/foo/bar/g, print for <>;.

Used where logicals are often seen, sequence expressions can be a sort of front-loaded continue block - without introducing a scope.

my ($i, $j) = (1, 10); while ($i++, $j--, $i < $j) { print "$i\t$j\n"; } __END__ 2 9 3 8 4 7 5 6
Note that increment and value of a variable in one expression are ok with C if they are seperated by the comma operator. That seems to work in Perl, too, as is sort-of-documented.

I think that that view of the sequence operator is not the usual one, but I find it useful. If there were an ultra-low precedence version like and and or, I'd call it then.

After Compline,
Zaxo


Comment on Re: True or False? A Quick Reference Guide
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-07-31 22:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (254 votes), past polls