Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

map perl looping from value

Tags:

perl

mason

I am not able to understand why following code is not working.

<%method getvivekBox>
  <%args>
   $BoxName
  </%args>

  <%perl>
    return {
      type        => 'vivek',
    };
  </%perl>
</%method>




<%method getAll>
 <%args>
  $BoxGroup
  $indexex
 </%args>
  <%perl>
    my $x =  map { $m->comp('SELF:getvivekBox' , BoxName => "$BoxGroup-$_"); } @$indexex;

    return $x;
  </%perl>
</%method>

I am calling getAll with arguments , box and (1..10). It is returning 11 but expected behavior for me it should return 10 elements.

like image 725
Vivek Goel Avatar asked May 26 '26 07:05

Vivek Goel


1 Answers

map on a list produces another list. You are assigning the result of the map to a scalar, thus getting the number of elements assigned to $x.

Change $x to @x, or put [] around the map (to make $x an array reference).

like image 56
2 revsasjo Avatar answered May 31 '26 16:05

2 revsasjo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!