jar00n has asked for the wisdom of the Perl Monks concerning the following question:
Hey guys,
Got a script I'm working and performance and speed are the name of the game. I have optimized a large portion of the code but this chunk stands out as something to fixed or done in a more correct way.
# Don't expand metacharacters $dir =~ s/\[/\\\[/g; $dir =~ s/\]/\\\]/g; $dir =~ s/\{/\\\}/g; $dir =~ s/\~/\\\~/g; $dir =~ s/\*/\\\*/g; $dir =~ s/\?/\\\?/g;
I feel like there's got to be a better way to handle this and that the better way would be faster. That snippet will be called hundreds of thousands of times and I'm looking to squeeze out as much performance as I can.
Any tips or advice would be excellent.
--Shields
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Faster way to regex this
by hdb (Monsignor) on Jun 08, 2014 at 09:39 UTC | |
by AnomalousMonk (Archbishop) on Jun 08, 2014 at 11:04 UTC | |
|
Re: Faster way to regex this
by Corion (Patriarch) on Jun 08, 2014 at 09:52 UTC | |
|
Re: Faster way to regex this
by davido (Cardinal) on Jun 08, 2014 at 15:42 UTC | |
|
Re: Faster way to regex this
by Anonymous Monk on Jun 08, 2014 at 09:38 UTC | |
|
Re: Faster way to regex this
by Anonymous Monk on Jun 08, 2014 at 10:09 UTC |