On 4/27/05, Peter Rabbitson <[EMAIL PROTECTED]> wrote:
> > also
> > "or die" is more preferable than "|| die"
> 
> Why is that? :) I was actually going to post a question about ambiguity
> syntax later, but here it is anyway. Are the following 4 equivalent?
> 

No.

> 1)
> if ($b) {
>   $a = $b;
> }
> else {
>   $a = $c;
> }

Pretty self explanatory

> 2)
> $a = $b or $c;

"=" has higher precedence than "or", so it parses as "($a = $b) or
$c".  $a will never equal $c.  Something else will equal either the
return value of ($a = $b)  or $c.

> 3)
> $a = $b || $c;
> 

Same as 1) because || has higher precedence than =.  So ti works in
this case.  But be careful with things like '$a = $b || $c = $d',
which will parse as '$a = ($b || $c) = $d'.

> 4)
> $a = $b ? $b : $c;
> 

Same as 1)

> Also there was an example on the web that completely threw me off. Although
> this works:
> 
> local ($/);
> 
> ,I have no idea how it undefs $/. Points to a good reading on the
> subject are equally appreciated.
> 

local declares a variable in a particular scope.  It saves the current
value of the variable, if any, and reinitializes the variable for the
duration of the curent scope (and only in the current scope).  In nine
case out of ten, local will be functionally equivalent to using my,
but It is exclusively for use with globals and package globals; trying
to use it with a normal lexical (I.e. "my") variable will throw an
exception.  See perldoc perlvar for details, and why you want to use
local instead of undef on built-ins (i.e., why 'local $/' is better
than 'undef $/' or '$/ = '' ').

HTH,

--jay

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to