I'm revisiting to undertand maps more...been reading the perldocs, almost there, but could use some clarification.

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.,

$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.' ],
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.


In reply to Re^3: Using map to convert an array into a hash of array of arrays by rjoost
in thread Using map to convert an array into a hash of array of arrays by rjoost

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.