$& and copying: rfc 158 (was Re: RFC 110 (v3) counting matches)
[email protected] (Uri Guttman)
| Newsgroups | perl.perl6.language.regex |
|---|---|
| Message-ID | <[email protected].> |
>>>>> "MD" == Mark-Jason Dominus <[email protected]> writes: MD> The $& cost is paid by every regex in the entire program, whether they MD> used it or not. This is because Perl has no way to tell which regexes MD> use $& and which do not. actually it is more like which code refers to $& and which regex that caem from. the problem stems from $& being a global and not local like $1. you can effective slow down all rgexes at a distance by using $& anywhere in your code since perl has no way of telling which regex might have been the last called when you copy $&. MD> One of Uri's suggestions in RFC 158 was to compute $& only for MD> regexes that have a /k modifier. This would solve the $& problem MD> because Perl would compute $& only when asked to, and not for MD> every other regex in the rest of the program. the rfc was about making $& private to the block with the regex and only make the copy if /k is used or you use grabbing. a side question i have is whether this extra copy is a runtime effect or compile time. i would imagine runtime with some global flag being checked to see if $& is being used. so you could run fast and later load a module uses $& which slows you down. in any case, i think we have a fair agreement on rfc 158 and i will freeze it if there is no further comments on it. uri -- Uri Guttman --------- [email protected] ---------- http://www.sysarch.com SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books The Best Search Engine on the Net ---------- http://www.northernlight.com