in reply to A C-like brain in a Perl-like world
Of course TMTOWTDI (variation on tachyon's theme, really):
sub unique_merge { my ( %hash ) = map {$_ => 1 } @_ ; return keys %hash } my @array1 = qw(a b c d e) ; my @array2 = qw(c d e f) ; my @merged_array = unique_merge(@array1, @array2) ;
Hashes may only have one key per value, so the task becomes how to get make a hash out of an array (or two). Using map I turn the arrays into key/value pairs (the value is not so important) and then ask for the keys back.
HTH
-Ducky
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: A C-like brain in a Perl-like world
by tilly (Archbishop) on Sep 27, 2001 at 00:01 UTC |