To interate over something like:

  $abc{'a1'}{'b1'} = $number1
  $abc{'a2'}{'b2'} = $number2
  $abc{'a3'}{'b3'} = $number3
  $abc{'a4'}{'b4'} = $number4
  ...

You can use:

  foreach my $key1 (keys %abc) {
    foreach my $key2 (keys %{$abc{$key1}}) {
      my $value = $abc{$key1}{$key2}
      print "Key1=$key1 Key2=$key2 Value=$value\n";
    }
  }


On Sat, 2002-12-07 at 02:46, Sean Rowe wrote:
> That sounds more like what I want to do.  I have a question, though: Since
> I'm not going to know before hand what my hash values are (as I create them
> on the fly), how can I iterate through each hash to get each value?  
> 
> -----Original Message-----
> From: Igor Sutton Lopes [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 06, 2002 10:12 AM
> To: [EMAIL PROTECTED]; Beginners@perl. org (E-mail)
> Subject: RES: Hash Question
> 
> 
> You can do something like this:
> 
> %url_options_hash = ("times_visited"=>0);
> %url_hash         = ("this_url"=>\%url_options_hash);
> %usr_hash         = ("igor"=>\%url_hash);
> 
> print $usr_hash{"igor"}->{"this_url"}->{"times_visited"}, "\n";
> $usr_hash{"igor"}->{"this_url"}->{"times_visited"} = 1;
> print $usr_hash{"igor"}->{"this_url"}->{"times_visited"}, "\n";
> 
> That worked for me, you use in this case the reference for the 'inner'
> hashes.
> 
> Igor.
> 
> 
> > ----- Mensagem original -----
> > De:         Sean Rowe [SMTP:[EMAIL PROTECTED]]
> > Enviada em:         sexta-feira, 6 de dezembro de 2002 11:30
> > Para:               Beginners@perl. org (E-mail)
> > Assunto:            Hash Question
> > 
> > I need to keep track of a user, all the web pages a user has visited, and
> > the number of times the user visited each page.  I get my information from
> a
> > log file.  Here's how I would like to say it programmatically:
> > 
> >     $Hash{"$User"}{"$Page"}{"$NumTimesVisited"} = $ANumber;
> > 
> > Is this possible?  If so, how would I traverse this, as I will not know
> > before hand the values in the hash; I will need to use something like
> sort.
> > Thank you.
> > 
> > Sean Rowe
> > 
> > 
> > -- 
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> 
> 
> ______________________________________________________________________
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to