So I should preface this by saying I've actually solved this, but the syntax is horrible so I want to see if theres a Perl-ish way of doing it which is nicer.
I have two arrays of length n (@genes and @names). I want to combine them into a single 2D array of paired values.
My approach right now is;
$Num = Number of elements in each array
my @genes = ();
foreach my $i ( 0 .. $num-1 ) {
foreach my $j ( 0 .. 1 ) {
if ($j == 0){ push @{ $genes[$i] }, $names[$i];}
if ($j == 1){ push @{ $genes[$i] }, $lengths[$i];}
}
}
But this requires an explicit line for each additional column (right now I have two - names and length). Also it's hideous. Code only a mother could love.
Any thoughts. Note that
@genes = (\@lengths, \@names);
Does not achieve what I want.
@namesand@lengththat you want to combine into a 2D-array@genes, I take it?