in reply to Having trouble looping through a data structure

One fishy thing about the example structure of the OP are sub-elements like
     'SKU' => [ 'CDS00013' ],
and
     'AvailableItems' => [ '100' ]

These imply there may be more than one value associated with each key, but I wonder if it is likely there will be more than one SKU number for a given item. If there will not be, don't put these elements in anonymous arrays.

Of course, the OP example may just be an extreme simplification of a much more complicated structure. If so, it may be worthwhile considering a re-organization of the structure. For instance, if the 'InternalSKU' represents one or more actual, 'external' SKUs (say, from different suppliers, each with its own inventory count), might something like the following be more appropriate for maintainability:

use warnings FATAL => 'all'; use strict; my %hash = ( article => [ { InternalSKU => '179', Name => 'wiggle', external_source => [ { mfg => 'AMD', SKU => 'CDS00013', count => 100, }, { mfg => 'Intel', SKU => 'FOO00099', count => 42, }, ], }, { InternalSKU => '180', Name => 'woggle', external_source => [ { mfg => 'AMD', SKU => 'CDS00014', count => 102, }, { mfg => 'Intel', SKU => 'BAR00042', count => 99, }, ], }, ], ); my $ref_to_article_anon_array = $hash{article}; for my $hashref (@$ref_to_article_anon_array) { my $i_sku = $hashref->{InternalSKU}; my $name = $hashref->{Name}; print "Name $name; Internal SKU: $i_sku; Source(s): \n"; my $grand_total = 0; for my $hr_external (@{ $hashref->{external_source} }) { # my $mfg = $hr_external->{mfg}; # my $sku = $hr_external->{SKU}; # my $count = $hr_external->{count}; my ($mfg, $sku, $count) = # either way works @$hr_external{ qw(mfg SKU count) }; $grand_total += $count; print " mfg $mfg; mfg's SKU: $sku; count: $count \n"; } print "total ${name}'s on hand: $grand_total \n\n"; }

Output:

Name wiggle; Internal SKU: 179; Source(s): mfg AMD; mfg's SKU: CDS00013; count: 100 mfg Intel; mfg's SKU: FOO00099; count: 42 total wiggle's on hand: 142 Name woggle; Internal SKU: 180; Source(s): mfg AMD; mfg's SKU: CDS00014; count: 102 mfg Intel; mfg's SKU: BAR00042; count: 99 total woggle's on hand: 201