1
\$\begingroup\$

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

asked May 10, 2013 at 15:28
\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$
@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
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.