Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
You can usually replace the innermost loop with a map.
?type use strict; use warnings; use Data::Dumper; my @array = ( [qw(0a 0b 0c 0d 0e 0f 0g 0h 0i 0j 0k)], [qw(1a 1b 1c 1d 1e 1f 1g 1h 1i 1j 1k)], [qw(2a 2b 2c 2d 2e 2f 2g 2h 2i 2j 2k)], [qw(3a 3b 3c 3d 3e 3f 3g 3h 3i 3j 3k)], [qw(4a 4b 4c 4d 4e 4f 4g 4h 4i 4j 4k)], ); my @array_new; foreach my $vec (@array) { push @array_new, [map {myfunc($_)} @$vec]; } print Dumper(\@array_new); sub myfunc { return "$_[0]_new"; } ?perl $VAR1 = [ [ '0a_new', '0b_new', '0c_new', '0d_new', '0e_new', '0f_new', '0g_new', '0h_new', '0i_new', '0j_new', '0k_new' ], [ '1a_new', '1b_new', '1c_new', '1d_new', '1e_new', '1f_new', '1g_new', '1h_new', '1i_new', '1j_new', '1k_new' ], ... ]; ?

In reply to Re: looping over multidimensional arrays by BillKSmith
in thread looping over multidimensional arrays by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (8)
    As of 2020-01-25 19:41 GMT
    Find Nodes?
      Voting Booth?