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

Re: regex expression help

by Animator (Hermit)
on Nov 08, 2005 at 18:10 UTC ( [id://506827]=note: print w/replies, xml ) Need Help??


in reply to regex expression help

The easiest way to get the part of the data before the string was found is to capture all of it.

Another approach is the one [id://Trix606] suggested... but be careful with it (as perlvar says): it impose a penalty on every regular expression... which slows down each match. Which is a bad idea.

Yet another approach is mentioned in the perlretut pod.

Some comments on this code. (Maybe relevant, maybe not.)

First, posting the code you are actually using might proof to be easier... and will result in better help.
(I say this because you have a syntax error in your code... (a missing ; after the print statement). This makes me guess that you didn't post the actual code)

Second, What if @dependantFiles contains a regex charachters? Do you want them to be interpreted or not? If not then you should look at the quotemeta function and/or \Q and \E in one of the perlre PODS (perlreref might be a good starting place).

Speaking about the regex: there is no need for the regex to be global. So drop the /g.

Another good idea is to use a lexical loop variable... it will make your live easier...

Doing next; at the end of the loop is pretty useless... (but it might make more sense in your actual code... (as in, the next is in an if-statement, and there is some other code behind it))

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2024-04-25 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found