swandown has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm building up a data structure using :
while (@fetch = $sth1->fetchrow) { $vendor = $fetch[0]; $terminal_id = $fetch[1]; $terminal_name = $fetch[3]; $refunds = $fetch[4]; $sales = $fetch[5]; $count = $fetch[6]; $vendor_sales{$vendor}{terminals}{$terminal_id}{terminal_name} + = $terminal_name; $vendor_sales{$vendor}{terminals}{$terminal_id}{sales} = $sale +s; $vendor_sales{$vendor}{terminals}{$terminal_id}{refunds} = $re +funds; $vendor_sales{$vendor}{terminals}{$terminal_id}{count} = $coun +t; }
It gives me the following structure :
'Book Shop' => { '10' => { 'count' => 222, 'refunds' => '90.00', 'sales' => '1200', 'terminal_name' => 'Front Till' }, '20' => { 'count' => 149, 'refunds' => '124.00', 'sales' => '7000.00', 'terminal_name' => 'Side Till' } }, 'Sweet Shop' => { '40' => { 'count' => 2, 'refunds' => '0.00', 'sales' => '400.00', 'terminal_name' => 'Cash Till +' }, '60' => { 'count' => 241, 'refunds' => '20.00', 'sales' => '600.00', 'terminal_name' => 'Credit Til +l' } }
How can I access the different elements in TT :
[% FOREACH vendor IN vendor_sales %] [% vendor.key %] : [% vendor.terminals.terminal_name %] [% END %]
Many Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing Array of Hashes in TT
by jeffa (Bishop) on Jun 18, 2013 at 17:58 UTC | |
|
Re: Accessing Array of Hashes in TT
by choroba (Cardinal) on Jun 18, 2013 at 17:57 UTC | |
|
Re: Accessing Array of Hashes in TT
by swandown (Novice) on Jun 18, 2013 at 18:27 UTC |