There are many ways to go about it, but here is one way:

#to enter the info:

my %errHash;          #the initial hash
$errHash{Jason} = []; #each hash element is an array
                      #each element of the array is a hash
push @{$errHash{Jason}},{date => "Jun1, 2003",error => "No Data"};

#to retrieve the info:

foreach(sort keys %errHash){
        print "$_\n";
        foreach my $record(@{$errHash{$_}){
                print "\t".$record->{date}."\t".$record->{error};
        }
}


Is that what you were looking for?

-----Original Message-----
From: Jason Normandin [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 12, 2003 5:29 PM
To: [EMAIL PROTECTED]
Subject: Multi-demensional, multi-key hash : Help :(

Hey Group

I am new to hashes, so please be kind : )

I am trying to create a hash of hash's with the following
characteristics:

1. The outer hash has a unique key called $ELEMENT 2. The value of the
outer hash is a key to the innner hash called $DATE 3. The value of the
inner hash is a value called $ERROR

I need to loop through some data which has multipe $DATE and $ERROR
entries per $ELEMENT and add them to the $ELEMENT hash based on the
$ELEMENT value.

Eg. Element Fred would have multiple DATE entries. Each date would have
one error.

I then need to iterate through the hash and display the element name(
only once if possible ), each timestamp and error.

Ex.

ELEMENT DATE            ERROR
jason           Jun 1, 2003     No Data
                Jun 4,2003      No Response
                July 1,2003     No Data
fred            Jan 2, 2002     No Response
                Jany 4,2002     Illegal value
....
..

This is just a dummy example. The real error types range and are unique.

Can anyone help with my constructing such a hash ?

I tried the following, which sucessfully creates the outerhash, but only
populates one value for each date, error pair:

        $snmpErr{$ELEMENT}= 
        {
                name => $ELEMENT,
                date => $DATE,
                error => $ERROR
        };

I then loop through via:

        foreach my $entry (keys %snmpErr)       
        {
                $el = $snmpErr{$entry}{name};   
                $ts = $snmpErr{$entry}->{date};   
                $er = $snmpErr{$entry}->{error};
        }

How far off am I ? : )

Thanks for the help all !!

- Jason



--
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