[ create a new paste ] login | about

Link: http://codepad.org/Gz2cIoAb    [ raw code | output | fork ]

Perl, pasted on Dec 3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/perl
use strict;
use warnings;

my @a = ( 'b', 'c', 'f' );
my @b = ( 'a', 'd' );
my @c = ( 'c', 'd', 'e' );

my %seen;
my @suniq = sort grep {!$seen{$_}++} @a, @b, @c;
foreach my $arr (\@a, \@b, \@c) {
    my %th = map { ( $_ => 1 ) } @$arr;
    @$arr = map { $th{$_} ? $_ : undef } @suniq;
}

use Data::Dumper;
print Dumper(\@a,\@b,\@c);


Output:
$VAR1 = [
          undef,
          'b',
          'c',
          undef,
          undef,
          'f'
        ];
$VAR2 = [
          'a',
          undef,
          undef,
          'd',
          undef,
          undef
        ];
$VAR3 = [
          undef,
          undef,
          'c',
          'd',
          'e',
          undef
        ];


Create a new paste based on this one


Comments: