DZone 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
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;
}






Comments
Snippets Manager replied on Fri, 2007/02/02 - 10:03pm