in reply to accessing a hash of hashes

foreach my $key (keys %urls) { print $urls{$key}{id}; }

Replies are listed 'Best First'.
Re^2: accessing a hash of hashes
by existem (Sexton) on Feb 15, 2005 at 11:44 UTC

    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

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