in reply to ||= oddity
So it seems that ||= generally isn't supported in perl.$ perl -MO=Deparse -e '@bar ||= (1,2,3)' Can't modify array dereference in logical or assignment (||=) at -e li +ne 1, at EOF -e had compilation errors. @bar ||= ('???', '???', 3); $ perl -MO=Deparse -we '@foo ||= 1' Can't modify array dereference in logical or assignment (||=) at -e li +ne 1, at EOF -e had compilation errors. BEGIN { $^W = 1; } @foo ||= 1;
Update: ok, other monks explained why. ||= returns a scalar.
A quick code search shows that all examples "out there" use it only in lines that are commented out, so it seems to be a common mistake actually
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: ||= oddity
by throop (Chaplain) on May 28, 2008 at 22:39 UTC | |
by why_bird (Pilgrim) on May 29, 2008 at 08:44 UTC | |
by moritz (Cardinal) on May 29, 2008 at 08:50 UTC | |
Re^2: ||= oddity
by jds17 (Pilgrim) on May 29, 2008 at 14:00 UTC |