Skip to content

Instantly share code, notes, and snippets.

@choroba
Last active August 29, 2015 14:10
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 choroba/4be98adb9425bd40ba0d to your computer and use it in GitHub Desktop.
Save choroba/4be98adb9425bd40ba0d to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 3;
{ my @list;
sub init {
my %elem;
undef @elem{@_};
@list = sort keys %elem;
}
sub rewrite {
for my $i (0 .. $#list) {
splice @_, $i, 0, undef unless defined $_[$i] and $_[$i] eq $list[$i];
}
return @_
}
}
my @a = qw( b c f );
my @b = qw( a d );
my @c = qw( c d e );
init(@a, @b, @c);
is_deeply([rewrite(@a)], [ undef, 'b', 'c', undef, undef, 'f' ], 'a');
is_deeply([rewrite(@b)], [ 'a', undef, undef, 'd', undef, undef ], 'b');
is_deeply([rewrite(@c)], [ undef, undef, 'c', 'd', 'e', undef ], 'c');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment