[tpm] Stupid question time!
Uri Guttman
uri at StemSystems.com
Sat Jan 30 16:42:50 PST 2010
>>>>> "MK" == Madison Kelly <linux at alteeve.com> writes:
MK> Ah, ya, I thought "!" and "not" where equiv. I switched all of my "!"
MK> to the word "not" to make the code more readable. Oh well, now I know.
i just posted to comp.lang.perl.misc about this. seems appropriate to
repost it here:
'and' and '&&' do the exact same operation. the ONLY difference is
precedence. this is true for all the boolean ops which have symbolic and
spelled out names. the spelled out names were added to perl5 later. they
were made lower precedence on purpose so you could do boolean ops which
bind lower than things such as assignment, func calls, etc.
the reason they are there is so you can have a CHOICE in precedence. it
allows for different syntax and some like it one way or the other.
look at these two common lines:
open( my $foo, $file ) || die "can't open $file $!" ;
open my $foo, $file or die "can't open $file $!" ;
the 'or' allows you to drop the () on the open call.
a good rule (courtesy of peter scott) about when to use which form is:
use the symbolic forms (||, &&, !) when doing a boolean expression
use the spelled forms( or, and, not) when doing flow control
the precedence levels work best in those situations.
$foo = $bar and last ;
$foo = $bar || $default ;
uri
--
Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
More information about the toronto-pm
mailing list