in reply to Having trouble looping through a data structure
Dear friend,
you can use this below code for accessing actual data..
#!/usr/bin/perl + use strict; use warnings; use Data::Dumper; my ($hash); $hash = { 'article' => [ { 'SKU' => [ 'CDS00013' ], 'InternalSKU' => '179', 'AvailableItems' => [ '100', '200' ] }, { 'SKU' => [ 'CDS00014' ], 'InternalSKU' => '180', 'AvailableItems' => [ '102' ] } ] }; my($key_1,$value,$data); foreach my $key (keys %$hash){ foreach my $element (@{$hash->{$key}}){ while (($key_1, $value) = each %$element){ #print $key_1,"\n"; if(ref($value) eq "ARRAY") { foreach $data (@{$value}) { print "Actual hash of array data:$data\n" } }else { print "hash Value:$value\n"; } } } }
|
|---|