in reply to Difference Quantity of two Arrays
The 1st pass through map allows "user" and "smtp". ("fetch" would be skipped.)
The 2nd pass through map allows "user" and "smtp". ("forward" would be skipped.)
The 3rd pass through map allows "smtp". ("user" is skipped.)
The 4th pass through map allows "user". ("smtp" is skipped.)
One solution (Set arithmetic using a hash):
sub create_list { my %dbs = map { $_ => 1 } qw/fetch forward user smtp/; delete @dbs{@_}; return keys %dbs; }
Another solution (Set arithmetic using a superposition):
use Quantum::Superpositions; sub create_list { my $dbs = any qw/fetch forward user smtp/; my $skip = all @_; return eigenstates( $dbs ne $skip ); }
Another solution (Set arithmetic using sets [seemed appropriate at the time]):
use Set::Scalar qw( ); sub create_list { my $dbs = Set::Scalar->new( qw/fetch forward user smtp/ ); my $skip = Set::Scalar->new( @_ ); return ($dbs - $skip)->members(); }
Update: Added second and third snippet.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Difference Quantity of two Arrays
by ocs (Monk) on Jan 02, 2007 at 15:30 UTC | |
by ikegami (Patriarch) on Jan 02, 2007 at 15:49 UTC |