You are aware that
will evaluate to the number of elements returned by foo rather than return the last one of them, right? :)
scalar (@x = foo(1,2,3,5));
Yes, of course. I wrote that in reference to my $x = foo(1); setting $x to 1 :oP
I agree that it would be a rare case when the flattened array would be an acceptable return value, but I still don't like the idea of throwing away data. Oh, well. The only alternative I can think of is the hideous
return wantarray ? @arr : $#arr ? \@arr : $arr;
which borders on the obfuscated. I wouldn't use something like that if I were you. Of course I'm me, and love using lines like that, but I digress...
Zaxo's suggestion of using $arr[-1] makes sense too, especially if the sub is doing something cumulative with its args. Imagine a sum() function that keeps track of all the intermediate sums, or whatever.
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||