> -----Original Message-----
> From: Sean Rowe [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 06, 2002 9:30 AM
> To: Beginners@perl. org (E-mail)
> Subject: 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;
No, it should probably look like this instead:
$Hash{$User}{$Page}++; # increment number of visits
Putting a single variable inside double quotes is useless. Also, you don't
need a third level in this hash. There are only two levels needed: user and
page.
>
> 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.
To print a table of users and the pages they have visited, you can do
something like:
for my $u (sort keys %Hash) {
for my $p (sort keys %{$Hash{$u}}) {
print "User $u visited page $p $Hash{$u}{$p} times\n";
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]