Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Scope Issue

by fidesachates (Monk)
on Mar 15, 2011 at 13:12 UTC ( [id://893315]=note: print w/replies, xml ) Need Help??


in reply to Re: Scope Issue
in thread Scope Issue

Am I wrong or did you mean || instead of //?

Replies are listed 'Best First'.
Re^3: Scope Issue
by AR (Friar) on Mar 15, 2011 at 13:21 UTC

    // is the defined or operator. || is the or operator. // and //= were added in in 5.10 as a shortcut for something along the lines of $var = defined $var ? $var : $default_value;

    $var //= $default_value; is much prettier IMHO. I'm fairly certain // and || short-circuit in the same exact way. It's easy enough to test.

      I tried || and // and they both worked. Thanks to everyone for your contribution!

        Note that || and // have different effects when the variable being tested is false! // only tests for undefined. || tests for any false value. ||= will replace 0 or '' with the right hand side value where //= will only replace undef with the right hand side value.

        //= behaves like:

        $var = $defaultValue if ! defined $var;

        ||= behaves like:

        $var = $defaultValue if ! $var;
        True laziness is hard work
Re^3: Scope Issue
by Anonymous Monk on Mar 15, 2011 at 13:19 UTC

    || is the regular or operator ("true, or ..." you might say).

    // is the defined or operator ("defined, or ...").

      ah. good deal.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://893315]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found