in reply to Re^3: ||= oddity
in thread ||= oddity
You're mostly right, but actually LHS || RHS in list context evaluates RHS in list context. Indeed, if you try
you see that the array is filled with the right values: (1, 2, 3); but that's still useless for indeed when the array isn't empty at the beginning,perl -we '@bar = (); @bar = @bar || (1, 2, 3); warn "(@bar)";'
the or operator returns the length of the array so the array will contain only (2).perl -we '@bar = (42, 5); @bar = @bar || (1, 2, 3); warn "(@bar)";'
Nice trap.
|
---|