precedence

C. Abney cabney at cyberpass.net
Fri Mar 10 16:01:24 CST 2000


~sdpm~
Just let me know if I'm a pain...

I was playing with error output in one of my scripts today, and here's
what I found:  Perl does pretty much what you expect.  Go figure.

This isn't always the case as I once found out (using something lame
like: "$opt_D ? $DEBUG = 1 : $DEBUG = 0;") but it was possibly worth it
because how often does one get email from Tom Christiansen and Uri
Gutman? <g>

Well I learned (a little bit, anyway) to read and test my assumptions
since then, and can test things like the following:

I have a line of code:

	system ( "$cmd" ) == 0
		or warn "failed remote copy: $!" unless $QUIET;

but I'm so brain dead that knowing 'or' is evaled left to right
isn't enough for me to be sure that its low precedence won't be
trumped by that of the 'unless'.  Too, 'unless' isn't listed in
the list of operators in which their precedence is scaled against
each others (that's 'perldoc perlop'.)  I had to test it.  I used
the following script:

	(2)[2136]$ cat or_unless.pl
	#! /usr/bin/perl
	$FOO = shift;
	$ERR = shift;
	$ERR or warn "gah!\n" unless $FOO;

Which, when executed, prints (or doesn't) the following:

	(2)[2136]$ ./or_unless.pl 1 1
	(2)[2136]$ ./or_unless.pl 1 0
	(2)[2136]$ ./or_unless.pl 0 1
	(2)[2136]$ ./or_unless.pl 0 0
	gah!
	(2)[2137]$ 

Unless I interpreted it wrong, I would have gotten a warning in the
second test if the 'unless' took precedence.  And I shouldn't have
had /any/ warnings in the third and fourth tests.

But... just ignore this.  I'm really just a overly chatty Perl
script.

CA
-- 
Einstein himself said that God doesn't roll dice. But he was wrong. And
in fact, anyone who has played role-playing games knows that God
probably had to roll quite a few dice to come up with a character like
Einstein.  -- Larry Wall                                     C. Abney

~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list