in reply to or or
Perl evaluates this:$a=$b || $c; $a=$b or $c;
This changes what gets assigned to $a, and can also change the context of a statement (from perlop):$a=($b || $c); ($a=$b) or $c;
This occurs because die is in scalar context, (so || is great for obfuscation!). || is also appropriate where you want to cause the rightmost value to get assigned. That is:@info = stat($file) || die; # oops, scalar sense of stat! @info = stat($file) or die; # better, now @info gets its due
Would assign $c to $a if $b was false, otherwise it would assign $b to $a. Whereas:$a=$b || $c
Would not assign $c to $a when $b was false! In scalar context, using || for dieing is fine, but you'll run into trouble with things where context is important. or is almost always what you mean in these cases.$a=$b or $c
If you still don't believe me, try this:
$a will be 0, and $b will be 1.$a=0 or 1; $b=0 || 1;
Andrew.
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Re: or or
by Aighearach (Initiate) on Jul 09, 2000 at 00:51 UTC | |
by ahunter (Monk) on Jul 09, 2000 at 01:57 UTC | |
by Aighearach (Initiate) on Jul 09, 2000 at 08:49 UTC |