I've actually run into this problem before. Correct me if I'm wrong, but the code that isn't working for you is:
push $cond > 0 ? @a : @b , $elem;
I remember reading somewhere that the ternary binds more closely than the conditional. This means that the ternary operator sees only the 0, assumes it to be a false condition, and then reports
@a back to the conditional statement.
@a would then be evaluated in scalar context and compared to
$code. No matter what the result, this eventually means that
push will be getting a boolean value (which may be null) instead of an array to push into. To fix this, simply enclose the conditional statement in parentheses, as below. This forces the conditional to evaluate first, followed by the ternary, which then reports to
push.
push ($cond > 0) ? @a : @b , $elem;
This is what has worked for me in the past. I'm currently on a handicapped (perl-less) machine, so I'm not able to test it. Someone please test and confirm.
Update: This explanation is completely wrong, and does not even work, as explained below. The problem is instead related to the prototyping in
push. My deepest apologies. Next time I will wait to consult the texts before answering.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.