> -----Original Message-----
> From: Chris Garringer [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 01, 2001 10:19 AM
> To: [EMAIL PROTECTED]
> Subject: Printing a data structure
>
>
> I have a data structure $logs[]{}{}[] that has the data
> parsed from a log file. I need to print the structure in a
> form that managment can understand. My problem is, I can
> fill the structure correctly but cannot seem to get a handle
> on printing it to allow printing the parts in a decent form. I tried
> foreach $day (@logs)
> {
OK, @logs is an array of hashrefs. So $day is a hashref. So far so good.
> ....some code1.....
> foreach $username (%$day)
> {
Problem here. %$day is a hash (dereferced via the $day hashref). When you
put a hash in the for (...) loop, it is "unrolled" into a flat list of
key/value pairs. So $username is assigned alternately a username (hash key)
and then a hashref (hash entry).
If you don't need the user name or don't care about the order in which
users are processed, you can use the values() function to get just the
hash entries as a list:
for my $userref (values %$day)
If you do need the user name, and/or you want to process users in sorted
order (for example), you need to use the keys() function to get just the
hash keys as a list:
for my $username (sort keys %$day)
{
my $userref = $day->{$username}; # get the hashref for this user
> .....some code2.....
> foreach $authmethod (%$username)
> {
Same problem here as above.
> .somecode .... the program never got here
> }
> }
> }
>
> I am still confused on Perl's reference/dereference
> symbology, so what am I doing wrong?
Make sense?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]