Skip to content

Instantly share code, notes, and snippets.

@jleader
Created December 2, 2014 21:22
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 jleader/fefa388194aad71193f9 to your computer and use it in GitHub Desktop.
Save jleader/fefa388194aad71193f9 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @a = ( 'b', 'c', 'f' );
my @b = ( 'a', 'd' );
my @c = ( 'c', 'd', 'e' );
my $i = 0;
my %map;
foreach my $k (sort @a, @b, @c) {
$map{$k} //= $i++;
}
my (@newa, @newb, @newc);
@newa[$i-1, @map{@a}] = (undef, @a);
@newb[$i-1, @map{@b}] = (undef, @b);
@newc[$i-1, @map{@c}] = (undef, @c);
print Dumper \@newa, \@newb, \@newc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment