Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: accessing a hash of hashes

by existem (Sexton)
on Feb 15, 2005 at 11:44 UTC ( #431120=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2022-08-14 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?