- my @a = x() | (1, 2, 3) evaluates x() and (1, 2, 3) in scalar context: x() gives 0 and (1, 2, 3) gives 3; now, the result (a single scalar) is put in a list context, resulting in a single-element list, so you have @a = (3) and it warns you that it threw away the (1, 2); it also warns (later, at runtime) that () in scalar context is undef and you are using an undef where you should be using a number
- my @a = x() || (1, 2, 3) evaluates x() in scalar context and (as x() gives you 0, false) evaluates (1, 2, 3) in list context, so you have @a = (1, 2, 3) and no warnings
- my @a = x() or (1, 2, 3) has different operator precedence; it could be written as (my @a = x()) || (1, 2, 3) -- it evaluates @a = x() in scalar context and (as x() gives you 0, false) evaluates (1, 2, 3) in void context, so the result of the left hand side of the "or" is (1, 2, 3) and it warns about throwing away the 1, 2 and the 3 :-)
- my @a = $c->bbox() || (1, 2, 3) evaluates $c->bbox() in scalar context (but in scalar context, bbox returns an array ref!!!) and does not evaluate (1, 2, 3) (it would, in list context, if the left hand side of the "or" were false), so you have @a = ([51,3,102,55]) and no warnings
- my @a = $c->bbox() or (1, 2, 3) has different operator precedence; it could be written as (my @a = $c->bbox()) || (1, 2, 3) -- it evaluates $c->bbox() in list context, but the whole @a = $c->bbox() in scalar context (the result of said assignment is 4, the lenght of the @a array now), so it will evaluate the (1, 2, 3) in void context, so the result of the left hand side of the "or" is (1, 2, 3) and it warns about throwing away the 1, 2 and the 3 :-)
So, what you really want is:
my @a = $c->bbox();
@a = (1, 2, 3) unless @a;
I don't have 5.10 installed here, so, I can't check if the "//" operator would do the trick for you... HTH!
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.