In another node i was replying and i wrote a piece of code which was not working. after some changes i made it work but i didn't figured out why wasn't. after some meditation i came up asking a friend, and seems like what didn't worked for me, worked for him.

i knew (but i checked perlop) that the ternary operator can be used as an lvalue (e.g.: $cond ? $a : $b = 0) and i expected it had worked on push too:

push $cond>0 ? @a : @b , $elem;
but the compiler complains (complaier?):
Type of arg 1 to push must be array (not null operation) at ...

push @{$cond>0 ? \@a : \@b}, $elem;
works as expected.

since my friend is serious enough, have i to think it works in other version of perl? (mine 5.8.4)
what exactly the compiler means with "null operation"?

PS: that's what i like of perl and perlmonks, trying to answer someone question i got a brand new one. :)
Oha


In reply to Using ternary operator as lvalue in push by oha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.