Try this. Note that I changed it so that OWNER and WAITING are arrayrefs, hence the push. You'll probably want to add data validation too...
Update:I made two late adjustments after 'strict'.
use strict; use warnings; use Data::Dumper; my %records; my $state; # UPDATE - Added this! while(<DATA>){ my @fields = split; # and added 'my' if ($fields[5] =~ /(OWNER|WAITING)/) { $state = $1; } else { push@{$records{$fields[1]}{$state}}, { USER => $fields[5], FILENAME => $fields[0], PID => $fields[6], TIME => $fields[9], DATE => "$fields[10] $fields[11]", ELAPSED => [] }; } } print Dumper(%records);
Partial Output:
$VAR21 = '001!SCHEDULE'; $VAR22 = { 'WAITING' => [ { 'PID' => '33', 'TIME' => undef, 'DATE' => ' ', 'ELAPSED' => [], 'FILENAME' => '/ud/QC-DATA/CONTROL', 'USER' => 'marshall' }, { 'PID' => '4565', 'TIME' => undef, 'DATE' => ' ', 'ELAPSED' => [], 'FILENAME' => '/ud/QC-DATA/CONTROL', 'USER' => 'steven' } ], 'OWNER' => [ { 'PID' => '500', 'TIME' => undef, 'DATE' => ' ', 'ELAPSED' => [], 'FILENAME' => '/ud/QC-DATA/CONTROL', 'USER' => 'richard' } ] };
In reply to Re^4: Perl Hashes, keys under keys (I think)?
by hbm
in thread Perl Hashes, keys under keys (I think)?
by mmartin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |