You can usually replace the innermost loop with a map.
?type 1222715.pl
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 1222715.pl
$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'
],
...
];
?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.