Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Having trouble looping through a data structure

by leslie (Pilgrim)
on May 17, 2010 at 10:14 UTC ( [id://840316]=note: print w/replies, xml ) Need Help??


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"; } } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://840316]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found