Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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,

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2021-01-24 00:06 GMT
Find Nodes?
    Voting Booth?