Try altering the following code to show your problem if it doesn't do what you are trying to achieve already:

use strict; use warnings; use Data::Dumper; my @prizes = ( { 'Timestamp' => '2005-11-07 11:18:01', 'WinnerId' => '2026', 'lineid' => '2026', }, { 'Timestamp' => '2005-01-07 11:18:01', 'WinnerId' => '2001', 'lineid' => '2001', }, { 'Timestamp' => '2005-05-07 11:18:01', 'WinnerId' => '2015', 'lineid' => '2015', }, ); my %month = ( '01' => 'January', '02' => 'February', '03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December', ); my @mapped_prizes = map {[$month{(split (/-/, $_->{'Timestamp'}))[1]} +=> $_]} @prizes; print Dumper (\@mapped_prizes);

Prints:

$VAR1 = [ [ 'November', { 'Timestamp' => '2005-11-07 11:18:01', 'lineid' => '2026', 'WinnerId' => '2026' } ], [ 'January', { 'Timestamp' => '2005-01-07 11:18:01', 'lineid' => '2001', 'WinnerId' => '2001' } ], [ 'May', { 'Timestamp' => '2005-05-07 11:18:01', 'lineid' => '2015', 'WinnerId' => '2015' } ] ];

Note that I removed some of the fields from the hash - only a couple are needed to demonstrate the issue. Note also that I added a couple of entries because it seems that more than one is required to show the issue. And further, note that I reduced the reference nesting by a level in the @prizes array which cleans up the warnings that I was seeing and also that I changed the +{}, in your original map (that looks rather peculiar) to a more usual {} and altered the contents of the map expression to do what I guess you want to do: generate an list of pairs of month and prize elements. I don't see why you don't want this as a hash however.


Perl is Huffman encoded by design.

In reply to Re^3: Is this a correct use of map? by GrandFather
in thread Is this a correct use of map? by BMaximus

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.