in reply to Re: Smartmatch alternatives
in thread Smartmatch alternatives
Or, avoiding full grep:
my $contains = sub { $_ eq $_[1] && return 1 for @{$_[0]}; 0 }; for (qw( Lisa Bart Fred LanX )) { [qw( Fred Wilma Barney Betty )]->$contains($_) and print; }
Though efficiency probably shouldn't enter the discussion here. Performing a key search on array, where you could have used a hash—bad decision. Another reason to dislike the smartmatch: it promotes bad design.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Smartmatch alternatives
by tobyink (Canon) on Dec 17, 2013 at 19:13 UTC |