in reply to Re: Keeping order, no duplicate and the complete keyset
in thread Keeping order, no duplicate and the complete keyset
The above assumes there are no dups in @big:
my @big = qw( a b c d e f g h i a ); my @small = qw( f c d g ); my %found; undef @found{@small}; my @wanted = ( @small, grep{ !exists $found{ $_ } } @big ); print("@wanted\n"); # f c d g a b e h i a
The OP's version removed dups fom @big, and so does the following version:
my @big = qw( a b c d e f g h i a ); my @small = qw( f c d g ); my %found; $found{$_}++ foreach @small; my @wanted = ( @small, grep{ !($found{$_}++) } @big ); print("@wanted\n"); # f c d g a b e h i
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Keeping order, no duplicate and the complete keyset
by BrowserUk (Patriarch) on Dec 08, 2005 at 06:10 UTC |