Output:use strict; use warnings; my @accounts = [ [ current => 1000 ], [ savings => 2000 ], [ other => 500 ], ]; foreach my $sub_ref (@accounts) { printf "%-10s | %10d\n", $_->[0], $_->[1] for @$sub_ref; }
Update: Seeing hazylife's EDIT in the code section, it came to my mind that my above code could also be simplified to:current | 1000 savings | 2000 other | 500
Please also note that my code might look slightly more complex (nested loops) because it is working on the OP's original AoA structure, whereas other solutions presented so far were just working on simple arrays.foreach my $sub_ref (@accounts) { printf "%-10s | %10d\n", @$_ for @$sub_ref; }
In reply to Re: [Solved] Printing a 2D array into constant-sized columns
by Laurent_R
in thread [Solved] Printing a 2D array into constant-sized columns
by mascip
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |