http://qs321.pair.com?node_id=630006


in reply to Re: Using ternary operator as lvalue in push
in thread Using ternary operator as lvalue in push

ouch... I'm oha's friend :-)

of course, I tested it with:
# This is perl, v5.8.7 my @a = (1,2,3); my @b = (4,5,6); push 1==1 ? @a : @b, "foo"; print "a=@a b=@b\n";
I even counter-checked (!) it with:
push 1==0 ? @a : @b, "foo";
to verify that the "foo" was pushed into @b.

of course, such stupid conditionals are optimized away. sorry for fooling myself, oha, and probably others. shame on me :-)

cheers,
Aldo

King of Laziness, Wizard of Impatience, Lord of Hubris

Replies are listed 'Best First'.
Re^3: Using ternary operator as lvalue in push
by FunkyMonk (Chancellor) on Aug 01, 2007 at 10:38 UTC
    Compile time constant removal magic.

    perl -MO=Deparse play produces:

    my(@a) = (1, 2, 3); my(@b) = (4, 5, 6); push @a, 'foo'; print "a=@a b=@b\n";

    /msg self Read ALL the post before replying