in reply to rearranging an array of arrays
Aside from this being a huge data set, as tilly has noted, I might do it this way.
use List::Util qw( max ); use List::MoreUtils qw( mesh ); # Find the length of the longest list. my $longest = max map { scalar @{ $_ } } @{ $foo }; # Pad every array to equal length using empty strings. push @{ $_ }, ( q{} ) x ( $longest - scalar @{ $_ } ) for @{ $foo }; # Since 'mesh' takes a list of arrays, using a prototype, # I use '&mesh' to avoid the prototype. my @meshed = &mesh( @{ $foo } ); # Alternate way to do the same thing #my @meshed = eval "mesh " . join q{,}, # map { "\@{ \$foo->[ $_ ] }" } 0 .. $#{ $foo }; # Pull out the individual rows. my $bar = []; push @{ $bar }, [ splice @meshed, 0, $longest ] while @meshed;
This preserves any undef in the original input.
It does more looping than it really needs to, but most of those loops are over the fairly small set of input arrays.
|
|---|