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.