Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Nilesh http://nilesh.org/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Perl: Sorted union of two arrays

Create a union of two arrays and sort the array.

my @union = array_union_sort(\@first, \@second);

sub array_union_sort {
    my $aa = shift;
    my $bb = shift;
    my %union;
    my $e;
    foreach $e (@$aa) { $union{$e} = 1; }
    foreach $e (@$bb) { $union{$e} = 1; }
    my @union = keys %union;
    @union = sort { $a <=> $b } @union;
    return @union;
}
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS