While
impossiblerobot and
tstock provided excellent solutions, it may help to understand why these solutions are needed.
When you
return() an array, it is sent back (so to speak) as a list. The variable
@array provides a nice little grouping for all its elements. If we had
@array = ('a', 'b'); and
return()'ed it, the portion catching this value will get
('a', 'b') and that variable container,
@array, is no more.
What does this lead to? Well, given the following:
sub foo { my @a = qw(a b); my @b = qw(c d); return (@a, @b); }<br>
@return_val = foo();
You might expect
@return_val to contain
('a', 'b')... But because the return value is put into a list,
('a', 'b', 'c', 'd') is returned from foo(). There aren't any
@a or
@b anymore to "draw the line" and distinguish one array from the other... it's just one big list.
So anyhow, by returning scalars (strings, hash refs, array refs, etc), you always ensure that the elements of each of the return values (or the elements pointed to by them) stay in their container variables. =)
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.