An AoA is an array of arrays. But in fact your structure is more complicated, it is an array containing a reference to an array of arrays (so it is really an AoAoA). I can't be sure of what you intended to do, but I would guess that you really wanted this:
my @accounts = (
[ current => 1000 ],
[ savings => 2000 ],
[ other => 500 ],
);
instead of this:
my @accounts = [
[ current => 1000 ],
[ savings => 2000 ],
[ other => 500 ],
];
The difference, if you don't see it, is in the round surrounding parens, versus square surrounding brackets. The first one (an AoA) looks like this:
0 ARRAY(0x80359d38)
0 ARRAY(0x80355ce8)
0 'current'
1 1000
1 ARRAY(0x80359d50)
0 'savings'
1 2000
2 ARRAY(0x803fe470)
0 'other'
1 500
and the second one is clearly more complicated, as it has one more level of nesting:
0 ARRAY(0x80359d38)
0 ARRAY(0x80356108)
0 ARRAY(0x80360410)
0 'current'
1 1000
1 ARRAY(0x80359c18)
0 'savings'
1 2000
2 ARRAY(0x80359bd0)
0 'other'
1 500
Ah, and yes, by all means, learn to use
sprintf and
printf, they are really useful as soon as you need to format output.
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.