Skip to content

Instantly share code, notes, and snippets.

@moritz
Created December 2, 2014 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/4421c5e9ab0e5d994bac to your computer and use it in GitHub Desktop.
Save moritz/4421c5e9ab0e5d994bac to your computer and use it in GitHub Desktop.
use 5.014;
use warnings;
my @in = (
[ 'b', 'c', 'f' ],
[ 'a', 'd' ],
[ 'c', 'd', 'e' ],
);
my %indexes = map {; $_ => 1} map @$_, @in;
my $count = scalar keys %indexes;
@indexes{sort keys %indexes} = 0 .. ($count - 1);
my @out = map {
my @new = (undef) x $count;
@new[ @indexes{@$_} ] = @$_;
\@new;
} @in;
use Data::Dumper;
print Dumper \@out;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment