Yesterday Steves was kind enough to provide me with the following code:
I've changed it slightly but it's essentially the same
Any idea how I can print element 0 of the lookup array containing the hash of arrays?foreach (@log_file) { chomp; next if ($_ =~ /^\s*$/); if ($_ =~ /^Date:\s+(.+)$/) { push(@lookup, $hash) if (defined($hash)); $hash = {DATE => $1}; } if ($_ =~ /^SServer:\s+(.+)$/) { $hash->{SSERVER} = $1; } elsif ($_ =~ /^Device:\s+(.+)$/) { $hash->{DEVICE} = $1; } elsif ($_ =~ /^CString:\s+(.+)$/) { $hash->{CSTRING} = $1; } elsif ($_ =~ /^Port:\s+(.+)$/) { $hash->{PORT} = $1; } elsif ($_ =~ /^SNMP Traps Generated:/) { $hash->{TRAPS} = {TRAP_LIST => []}; } elsif ($_ =~ /^\s+Trap OID:\s+(.+)$/) { $hash->{OID} = $1; } elsif ($_ =~ /^\s+Generic:\s+(.+)$/) { $hash->{GENERIC} = $1; } elsif ($_ =~ /^\s+Specific:\s+(.+)$/) { $hash->{SPECIFIC} = $1; } elsif ($_ =~ /^\s+Varbind:\s+(.+)$/) { $trap = {VARBIND => $1}; } elsif ($_ =~ /^\s+Type:\s+(.+)$/) { $trap->{TYPE} = $1; } elsif ($_ =~ /^\s+Data:\s+(.+)$/) { $trap->{DATA} = $1; push(@{$hash->{TRAPS}->{TRAP_LIST}}, $trap); } } push(@lookup, $hash) if (defined($hash)); print $lookup[0]{'SSERVER'}; print $lookup[0]{'DEVICE'}; print $lookup[0]{'TRAPS'}->{'TRAP_LIST'}; #returns an array ref
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |