Just to help illustrate how Perl 'flattens' or as I try to think of it (thanks to diotalevi)
'list-ifies' subroutine arguments consider the following
my @array = qw(arrayval1 arrayval2 arrayval3 arrayval4 arrayval5);
my %hash = (key1=>'val1', key2=>'val2', key3=>'val3');
arrayval1 arrayval2 arrayval3 arrayval4 arrayval5 key2 val2 key1 val1
ARRAY(0x1824320) key2 val2 key1 val1 key3 val3
arrayval1 arrayval2 arrayval3 arrayval4 arrayval5 HASH(0x182435c)
Notice in the output of the first call the keys and values from %hash
get tacked onto the end of the values in @array
as if the entire thing were one huge list. Now imagine trying to get keys or values from %hash
? Not likely nor easy.
In the second and third examples we pass one reference but the argument list is still just a list.
The final example is much cleaner. If you were confused about what you originally passed into the sub your could always call ref
and find out; otherwise there is no way to tell if you are passed a 'list-ified' hash or array.
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo
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.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||