Of course, you can make the change you want. It has nothing to do with map, we are actually talking about the ?: operator.

my $rows = [ map { my $row = $_; ($results > 0) ? { ODD => [ map { {VALUE => $_} } @{$row} ] } : { EVEN => [ map { {VALUE => $_} } @{$row} ] } } @{$data} ];
Pure guess, your problem might be where you defined your $results, and how you used it. be careful about one thing,
(++$i % 2)
is not just a condition, each iteration, it also alters the value of $i. but
($results > 0)
does not modify $results, unless being modified else where inside the map {}, it stays the same for each iteration, which might not be what you want.

Show more detail, I can update this post.

Update:

Okay, I can see what you are doing. I mimic'd what you were doing, and the result from the attached code make sense to me.

Pls modify the following code I attached, and add a third section, to show me your problem with $results.
use Data::Dumper; { my $data = [[0,1,2,3,4,5], [1,2,3,4,5,6], [2,3,4,5,6,7], [3,4,5,6,7,8], [4,5,6,7,8,9], [5,6,7,8,9,10]]; my $i = 0; my $rows = [ map { my $row = $_; (++ $i % 2) ? { ODD => [ map { {VALUE => $_} } @{$row} ] } : { EVEN => [ map { {VALUE => $_} } @{$row} ] } } @{$data} ]; print Dumper($rows); } { my $data = [[0,1,2,3,4,5], [1,2,3,4,5,-6], [2,3,4,5,6,7], [3,4,5,6,7,8], [4,5,6,7,8,9], [5,6,7,8,9,10]]; my $rows = [ map { my $row = $_; (@{$row}[5]>= 0) ? { ODD => [ map { {VALUE => $_} } @{$row} ] } : { EVEN => [ map { {VALUE => $_} } @{$row} ] } } @{$data} ]; print Dumper($rows); }
The result is:
$VAR1 = [ { 'ODD' => [ { 'VALUE' => 0 }, { 'VALUE' => 1 }, { 'VALUE' => 2 }, { 'VALUE' => 3 }, { 'VALUE' => 4 }, { 'VALUE' => 5 } ] }, { 'EVEN' => [ { 'VALUE' => 1 }, { 'VALUE' => 2 }, { 'VALUE' => 3 }, { 'VALUE' => 4 }, { 'VALUE' => 5 }, { 'VALUE' => 6 } ] }, { 'ODD' => [ { 'VALUE' => 2 }, { 'VALUE' => 3 }, { 'VALUE' => 4 }, { 'VALUE' => 5 }, { 'VALUE' => 6 }, { 'VALUE' => 7 } ] }, { 'EVEN' => [ { 'VALUE' => 3 }, { 'VALUE' => 4 }, { 'VALUE' => 5 }, { 'VALUE' => 6 }, { 'VALUE' => 7 }, { 'VALUE' => 8 } ] }, { 'ODD' => [ { 'VALUE' => 4 }, { 'VALUE' => 5 }, { 'VALUE' => 6 }, { 'VALUE' => 7 }, { 'VALUE' => 8 }, { 'VALUE' => 9 } ] }, { 'EVEN' => [ { 'VALUE' => 5 }, { 'VALUE' => 6 }, { 'VALUE' => 7 }, { 'VALUE' => 8 }, { 'VALUE' => 9 }, { 'VALUE' => 10 } ] } ]; $VAR1 = [ { 'ODD' => [ { 'VALUE' => 0 }, { 'VALUE' => 1 }, { 'VALUE' => 2 }, { 'VALUE' => 3 }, { 'VALUE' => 4 }, { 'VALUE' => 5 } ] }, { 'EVEN' => [ { 'VALUE' => 1 }, { 'VALUE' => 2 }, { 'VALUE' => 3 }, { 'VALUE' => 4 }, { 'VALUE' => 5 }, { 'VALUE' => -6 } ] }, { 'ODD' => [ { 'VALUE' => 2 }, { 'VALUE' => 3 }, { 'VALUE' => 4 }, { 'VALUE' => 5 }, { 'VALUE' => 6 }, { 'VALUE' => 7 } ] }, { 'ODD' => [ { 'VALUE' => 3 }, { 'VALUE' => 4 }, { 'VALUE' => 5 }, { 'VALUE' => 6 }, { 'VALUE' => 7 }, { 'VALUE' => 8 } ] }, { 'ODD' => [ { 'VALUE' => 4 }, { 'VALUE' => 5 }, { 'VALUE' => 6 }, { 'VALUE' => 7 }, { 'VALUE' => 8 }, { 'VALUE' => 9 } ] }, { 'ODD' => [ { 'VALUE' => 5 }, { 'VALUE' => 6 }, { 'VALUE' => 7 }, { 'VALUE' => 8 }, { 'VALUE' => 9 }, { 'VALUE' => 10 } ] } ];

In reply to Re: Mapping Logic by pg
in thread Mapping Logic by Anonymous Monk

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.