Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Smartmatch alternatives

by oiskuu (Friar)
on Dec 17, 2013 at 17:20 UTC ( #1067504=note: print w/ replies, xml ) Need Help??


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.


Comment on Re^2: Smartmatch alternatives
Download Code
Re^3: Smartmatch alternatives
by tobyink (Abbot) on Dec 17, 2013 at 19:13 UTC

    It makes sense to use hash keys if all the items being searched through are strings. If some of them are regexps, coderefs, objects with overloading, etc., then a hash is not an option.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-12-21 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (102 votes), past polls