Just another Perl shrine | |
PerlMonks |
Re: Pimp My RegExby demerphq (Chancellor) |
on May 31, 2005 at 18:51 UTC ( [id://462166]=note: print w/replies, xml ) | Need Help?? |
Your regex is really horribly inefficient. Think about what it has to do to match that pattern. A much simpler way to do the same thing is:
Ie you know that when a line starts with a data that it begins a record, this also implys it denotes the end of the previous record (if such a record exists). Thus you simply need to check each line to see if it begins the record, and then do something with the previous one that you have constructed. This also means that the pattern is anchored and only needs to compare Lr (the length of pattern) chars per line instead of the the Lf (the length of the file) times Lr that your code would do (with the look ahead assertion). So your pattern does something like 55000000*23 character lookups, even worse most of those will be char class lookups so they are inefficient to start with. If you use the line by line approach you are dealing with 366000*23 lookups. Thats a LOT less. (Actually these are upper bounds, but i think the point is made) Update:Fixed as per ikegami's reply.
--- $world=~s/war/peace/g
In Section
Seekers of Perl Wisdom
|
|