Re: Question about || (was REGEXP removing - il- - -b-f and - il- - - - f)



On 4/27/05, Peter Rabbitson <rabbit@xxxxxxxxx> 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
.



Relevant Pages

  • Re: RfD - Enhanced local variable syntax, v4 (long)
    ... My syntax is from spring 1992, ... I prefer the automatic scoping, too, but won't recommend it for a standard ... A simpler form would be that locals are visible at least up to the ... be with SCOPE ... ...
    (comp.lang.forth)
  • Re: Ruby blocks in Python, a suggestion
    ... A function really is just a special case of a code block that ... scope and the calling scope. ... This syntax preserves that relationship, ... def my_codeblock: ...
    (comp.lang.python)
  • Re: Customizing Delegwiz.inf syntax question
    ... new to the syntax. ... find the list of the "SCOPE" identifiers? ... I want to find the correct identifiers for the .SCOPE object types for ... and computer account management. ...
    (microsoft.public.windows.server.active_directory)
  • Re: New bytecode assembly language to play with
    ... C syntax does have its deficiencies. ... many languages have. ... only available within the scope of a single function to be a pretty ... A globally declared function can only see ...
    (comp.lang.misc)
  • Re: Error Trapping Within Classes
    ... It looks like that was outside the scope of the ... Before the script is run it gets parsed which includes checking the ... syntax. ... for the errors outside of the custom error trapping scope (such ...
    (comp.lang.php)