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

It looks like there really is a difference in the calling context:
#!/usr/bin/perl use Carp; my $ret; undef $ret; ($ret) ||= foo(); warn "ret is $ret"; undef $ret; ($ret) = $ret || foo(); warn "ret is $ret"; sub foo { carp "Want " . (wantarray ? "array" : "scalar"); (1,2); }
outputs:
Want scalar at t3 line 17 main::foo() called at t3 line 8 ret is 2 at t3 line 9. Want array at t3 line 17 main::foo() called at t3 line 12 ret is 1 at t3 line 13.

Replies are listed 'Best First'.
Re^3: Why are "a ||= b" and "a = a || b" different?
by Anonymous Monk on Mar 05, 2007 at 10:07 UTC
    void is false
    my $w = wantarray; $w = defined $w ? ($w ? 'list' : 'scalar') : 'void'; carp "wantarray : $w ";

      Why copy the value of wantarray into a temporary? You're just adding visual and other overhead.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊