in reply to Why are "a ||= b" and "a = a || b" different?

You could just say $ret ||= (foo())[0]; instead.

Replies are listed 'Best First'.
Re^2: Why are "a ||= b" and "a = a || b" different?
by ikegami (Patriarch) on Mar 05, 2007 at 07:04 UTC

    The equivalent would actually be

    $ret ||= (foo())[-1];

      I'm affraid no.

      sub foo { wantarray or die "this function is called in list context in all ex +amples"; "alpha", "beta", "gamma"; } $ret = undef; ($ret) = $ret || foo(); print "parenthetical: $ret\n"; $ret = undef; $ret ||= (foo())[0]; print "zero: $ret\n"; $ret = undef; $ret = (foo())[-1]; print "minus one: $ret\n";
      Gives
      parenthetical: alpha zero: alpha minus one: gamma
        My apologies. My test was wrong.