Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Perl Hashes, keys under keys (I think)?

by mmartin (Monk)
on Sep 20, 2011 at 19:27 UTC ( #927009=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Perl Hashes, keys under keys (I think)?
in thread Perl Hashes, keys under keys (I think)?


Hey hbm,

Thanks for the reply. Good idea! You guys are so good at condensing code down to the bare minimum. I always seem to have a case of "code bloat".

Only thing is, is that it will only do up to one WAITING user. That was one of the problems I ran into as well. Somewhere there would have to be something where it should, for instance, "Once you do a WAITING record, keep doing it until the line contains 'OWNER'".

But really thanks for the suggestion. I will play around with your condensed version and see if I can get it to run properly.



Thanks Again,
Matt



.


Comment on Re^3: Perl Hashes, keys under keys (I think)?
Re^4: Perl Hashes, keys under keys (I think)?
by hbm (Hermit) on Sep 20, 2011 at 20:03 UTC

    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' } ] };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://927009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-07-30 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls