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'
],
...
];
?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.