XP is just a number | |
PerlMonks |
Re: Regexes eating too much RAMby diotalevi (Canon) |
on Mar 04, 2006 at 06:08 UTC ( [id://534428]=note: print w/replies, xml ) | Need Help?? |
In general, the recipe is to eliminate all capture groups that operate on your large string. Beyond that, you can try to cut things off as you process them. Perl keeps a marker about where a string begins so if you're contientious, you can convince perl to just advance that pointer. This is wasteful. When it matches, it makes a copy of $_ to an internal buffer so $1 can refer back to it. Eliminate the capturing parentheses and use substr() with @- and @+ to refer back to what $1 would have contained. The documentation for @- is a good reference for you right now. You'll notice how I used 4-arg substr to directly replace the first part of the string.
Efficient.
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
In Section
Seekers of Perl Wisdom
|
|