http://qs321.pair.com?node_id=431120


in reply to Re: accessing a hash of hashes
in thread accessing a hash of hashes

Thanks for the reply, that would work for my example, but I should have explained that I don't actually know the value of ID all the time, so infact my structure might look more like this:

$urls{'networkid'}{'someidIdontknow'}='somevalue1'; $urls{'networkid2'}{'someidIdontknow2'}='somevalue2'; $urls{'networkid3'}{'someidIdontknow3'}='somevalue3';

So unfortunately I can't access the value I don't know directly, but need a means to loop through all the values.

From looking at the post above I now have this code but it doesn't work.

foreach my $network (keys %urls) { foreach my $key (keys %$network) { print "$key<br/>"; } }

Any ideas where i'm going wrong? I know it's something to do with accessing the hashref.

Cheers, Tom

Replies are listed 'Best First'.
Re^3: accessing a hash of hashes
by Thilosophy (Curate) on Feb 15, 2005 at 11:54 UTC
    foreach my $network (keys %urls) { foreach my $key (keys %{$urls{$network}}) { print "$key<br/>"; } }
    or
    foreach my $network (values %urls) { foreach my $key (keys %$network) { print "$key<br/>"; } }