I have the following data structure defined:

my @clients = (
    {
        name    => 'joe',
        count   => [ qw( one two three ) ]
    }
);

Then I try running the following routine:

for my $client (@clients) {
    for my $i ($client->{count}) {
        print "$i\n";
    }
}

I expect it to print the following:
one
two
three

But instead, it prints out the following:
ARRAY(0x8b4b880)

If I change it to:
    for my $i (@$client->{count}) {
        print "$i\n";
    }

I get the error:
Not an ARRAY reference at ./test_data_structure.pl line 12.


My question is what am I doing wrong?  How to I loop over each element
in my anonymous array to process it?  I've read the data structure
tutorials and tried different things, but just can't seem to get this to
work.

Any suggestions would be highly appreciated.


Pablo


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to