in reply to Re^2: Scope Issue
in thread Scope Issue

// 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.

Replies are listed 'Best First'.
Re^4: Scope Issue
by MKJ747 (Acolyte) on Mar 15, 2011 at 13:51 UTC

    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