Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: one line to check for common list values

by Anonymous Monk
on Feb 25, 2017 at 18:12 UTC ( [id://1182830]=note: print w/replies, xml ) Need Help??


in reply to one line to check for common list values

There's a trick for jamming an expression into a string or regex:

my @result = "@input" =~  /@{[join "|", map "\\b$_\\b", @valuesToMatch]}/g;

But you're probably better off using a hash for this. It'll be much faster if the arrays are large.

my %match; $match{$_} = 1 foreach @valuesToMatch; my @result = grep $match{$_}, @input;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-23 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found