Problems? Is your data what you think it is? | |
PerlMonks |
Re: Perl noob struggling to loop through an arrayby aitap (Curate) |
on Oct 24, 2012 at 15:52 UTC ( [id://1000661]=note: print w/replies, xml ) | Need Help?? |
Greetings, Microkorg.
Your code is OK, but please don't use $& because it can slow down your other regexps. Catch symbols using (regexp) and use them as $number_of_catch_group, like this:
WARNING: Once Perl sees that you need one of $&, "$`", or "$'" anywhere in the program, it has to provide them for every pattern match. This may substantially slow your program. Perl uses the same mechanism to produce $1, $2, etc, so you also pay a price for each pattern that contains capturing parentheses. (To avoid this cost while retaining the grouping behaviour, use the extended regular expression "(?: ... )" instead.) But if you never use $&, "$`" or "$'", then patterns without capturing parentheses will not be penalized. So avoid $&, "$'", and "$`" if you can, but if you can't (and some algorithms really appreciate them), once you've used them once, use them at will, because you've already paid the price. As of 5.005, $& is not so costly as the other two.Seen at perlre, right before Quoting metacharacters.
Sorry if my advice was wrong.
In Section
Seekers of Perl Wisdom
|
|