in reply to Array splice ??
I've rudely assumed "Trap OID", "Generic", and "Specific" actually belong in a trap rather than the entry. If that's not the case you can easily edit it ofcourse.use strict; use warnings; use Data::Dumper; sub readlogfile { my ($filename) = @_; open my $logfile, '<', $filename or die "open $filename: $!"; my (@lookup, $entry, $trap); while (<$logfile>) { chomp; if ( /^Date:\s+(.+)$/ ) { push @lookup, ($entry = { DATE => $1 }); undef $trap; } elsif ( !$entry ) { next; } elsif ( /^(SServer|Device|CString|Port):\s+(.+)$/ ) { $entry->{uc $1} = $2; } elsif ( /^\s+(Trap OID|Generic|Specific|Varbind|Type):\s+(.+ +)$/ ) { $trap->{uc $1} = $2; } elsif ( /^\s+Data:\s+(.+)$/ ) { push @{$entry->{TRAPS}{TRAP_LIST}}, $trap if $trap; $trap = { DATA => $1 }; } } return @lookup; } print Dumper readlogfile("logfile.txt");
In any case I hope this is useful for solving your problem
|
|---|