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

Re: Perl Regexp help w/ grep

by injunjoel (Priest)
on Oct 14, 2005 at 17:08 UTC ( [id://500315]=note: print w/replies, xml ) Need Help??


in reply to Perl Regexp help w/ grep

Greetings all,
Here is my suggestion.
#the following is untested. my @local_files = grep /^$id.*?_arbv_/i, readdir LOCALDIR;
The . matches any character. The * matches the previous character 0 or more times and the ? keeps it from being too greedy (well in concert with * that is) So it matches the shortest amount possible not the longest.

-InjunJoel
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

Replies are listed 'Best First'.
Re^2: Perl Regexp help w/ grep
by revdiablo (Prior) on Oct 14, 2005 at 19:00 UTC
    the ? keeps it from being too greedy

    I'm curious, what is the purpose of including this in a simple match? Seems to me that it would only make sense if it was a capturing match or a search and replace. Not that there's anything wrong with it, it just seems a bit pointless.

      Perhaps it's an attempt at optimization? A greedy RE will match the entire filename from that point on and then have to back track character by character to determine if there is or isn't a match. By making the RE non-greedy, matching filenames will be found faster.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-24 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found