\$\begingroup\$
\$\endgroup\$
0
Looking for a cleaner (possibly one liner) way to write the following
my $spec_2d = ( );
foreach ( @spec ) {
$spec_2d[$_][0] = $spec[$_];
}
@spec = @spec_2d;
Basically I'm making an array an array of arrays
1 Answer 1
\$\begingroup\$
\$\endgroup\$
@spec_2d[@spec] = map [ $spec[$_] ], @spec;
but judging from the subject I think you want this,
my @spec_2d = map [ $_ ], @spec;
answered May 10, 2013 at 19:53
lang-perl