Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Reverse grep?

by chipmunk (Parson)
on Mar 02, 2002 at 17:23 UTC ( #148853=note: print w/replies, xml ) Need Help??

in reply to Reverse grep?

By "reverse grep", I take it that you mean you want to loop over a list of regexes with one string, rather than loop over a list of strings with one regex. As far as Perl is concerned, these are the same.

Your difficulty comes from thinking of Perl's grep as being the same as the command line grep. This is not the case. In Perl's grep, the conditional is not necessarily a pattern match; it is any arbitrary Perl expression. For example, you could do something like this: @results = grep { $_ & 1 } (1 .. 10)
to get a list of odd numbers between 1 and 10.

Thus, you can do any filtering you want with grep, with the proper conditional expression. What you're looking for could be written something like this (with some regexes I made up):

my $url = ''; my @regexes = ('/private(?:/|$)', 'python'); if (grep { $url =~ $_ } @regexes) { # handle bad URL } else { # handle good URL }
As suggested in another response, you'd probably want to precompile the regexes with qr// for efficiency.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://148853]
[choroba]: and in fact, you don't push into the target repo, you push into your branch of your fork
[choroba]: the maintainer of the upstream repo than "merges" the pull request, i.e. they pull from your fork into the upstream
[Discipulus]: ' i.e. you asked them to pull from your repo' =~ I (subj) want to push
[Discipulus]: chorobayour words are reasonable
[choroba]: I'm just repeating some else's words as I remembered them after having asked the same question
[choroba]: s/some/someone/
Discipulus what a pity all people do not speak only in eatalian..
[choroba]: we'd need video calls more often :)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2017-05-27 20:15 GMT
Find Nodes?
    Voting Booth?