Jason Normandin wrote: > > Hey Group Hello,
> 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 > }; my %snmpErr = ( 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' } ); > I then loop through via: > > foreach my $entry (keys %snmpErr) > { > $el = $snmpErr{$entry}{name}; > $ts = $snmpErr{$entry}->{date}; > $er = $snmpErr{$entry}->{error}; > } for my $name ( keys %snmpErr ) { for my $date ( keys %{$snmpErr{$name}} ) { print "Name: $name Date: $date Error: $snmpErr{$name}{$date}\n"; } } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]