Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Need RegExp help - doing an AND match

by imp (Priest)
on Jul 01, 2007 at 13:55 UTC ( #624303=note: print w/ replies, xml ) Need Help??


in reply to Need RegExp help - doing an AND match

Here's one way to do it with regex:

use strict; use warnings; my $re = qr{ ^ (?=.*foo) (?=.*bar) }x; while (my $line = <DATA>) { print $line if $line =~ $re; } __DATA__ foo bar foo bar bar foo abc foo bar


Comment on Re: Need RegExp help - doing an AND match
Download Code
Re^2: Need RegExp help - doing an AND match
by Anonymous Monk on Jul 01, 2007 at 14:14 UTC
    Oh, hang on a second, there was a valid reason why I wanted RegExp, actually, I forgot.

    grep will still search the whole array @words, right?

    My original code terminates as soon as it fails to match one word in the array which is what I wanted as the file is huge.
    Ok, it's not the best code at all, but it doesn't have to search the entire array every time.

    I haven't benchmarked to check yet, but I guess grep might take longer.

    I was hoping for a RegExp that stopped its search on a mismatch so I think your second solution might be faster, I will check.

    Thanks!
      The List::Util module has a first function which may be what you want here instead of grep.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-09-16 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (9 votes), past polls