The stupid question is the question not asked | |
PerlMonks |
Re: regex expression helpby Animator (Hermit) |
on Nov 08, 2005 at 18:10 UTC ( [id://506827]=note: print w/replies, xml ) | Need 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.
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))
In Section
Seekers of Perl Wisdom
|
|