in reply to Re^2: Using map to convert an array into a hash of array of arrays
in thread Using map to convert an array into a hash of array of arrays
If I've got Dumper output like this:
$VAR1 = [ '2100', [ '2010-08-12', '12:23:56', 'INFO', '2100', 'some stuff, REPA0.prm: Executing DDL operation.' ], '2100', [ '2010-08-12', '12:23:56', 'INFO', '2100', 'some output, REP.prm: DDL operation is of default scope. +' ],
With a data structure of an array of arrays, where the first "element" is 2100 in this example,
I'd like to convert this into a Hash of array of arrays where 2100 is the hash key to an array of arrays.
%alertlog = map { $_->[0] => [ $_->[2], $_->[3], $_->[4], $_->[5], $_ +->[6] ]; } sort { Date_Cmp($a->[1], $b->[1]) } map { chomp; @loglines = split(/\s+/, $_, 5); $timestring = $loglines[0] . ' ' . $loglines[1]; [ $loglines[3], (ParseDate($timestring), $loglines[0], $lo +glines[1], $loglines[2], $loglines[3], $loglines[4]) ]; } @messages;
This creates a hash of arrays just fine, but it flattens out the array of arrays.
In the original array of arrays, the $_->[0] referred to above is always the first element in an array of arrays.
Below, the "2100" key should show, as it's hash value, an array of arrays....... And likewise for any "key" which has one or more arrays as its resultant value.
DUMP OF %alertlog from check_alertlog(): $VAR1 = { '109' => [ '2010-08-13', '17:42:58', 'ERROR', '109', 'some stuff, .... SQL <UPDAT...' ], '190' => [ '2010-08-13', '17:42:58', 'ERROR', '190', 'another message ' ], '2100' => [ '2010-08-12', '21:18:53', 'INFO', '2100', 'another message...' ] };
So, from the array which was passed, and, from which, using map, I'm trying to create a hash of arrays of arrays, the map I've got so far, creates a hash of arrays just fine, BUT it doesn't do a hash of arrays of arrays properly...
If I make the map output an array of arrays, it works for that just fine and outputs, e.g.,
If I could take that output, in the map, and make "2100" the hash key to an array of arrays, that's what I am trying to do.. under time pressure so will go back to the docs tonight and keep trying as time and life permit.$VAR1 = [ [ '2100', '2010-08-12', '15:34:37', 'INFO', '2100', 'bunch of info: Executing operation.' ], [ '2100', '2010-08-12', '15:34:37', 'INFO', '2100', 'bunch of info: operation is of unmapped scope.' ], [ '2100', '2010-08-12', '15:34:37', 'INFO', '2100', 'bunch of info, REP.p: Executing operation.' ],
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Using map to convert an array into a hash of array of arrays
by rjoost (Novice) on Aug 17, 2010 at 08:26 UTC |