Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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

share|improve this question

1 Answer

@spec_2d[@spec] = map [ $spec[$_] ], @spec;

but judging from the subject I think you want this,

my @spec_2d = map [ $_ ], @spec;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.