Wednesday, November 23, 2011

A short perl code to find union of 2 arrays in perl

Using slices on hash variable :)

sub array_union {
    my ($arrRef1, $arrRef2) = @_;
    my %hash;
    @hash{@$arrRef1} = undef;
    @hash{@$arrRef2} = undef;
    return keys %hash;
}