|
From: Dr.Ruud on 3 Nov 2005 22:29 Abigail: > Ruud: > does "$re{A01}[SRCH]" change? No, it's a constant. > If the first > question is answered with 'no', then using /o doesn't matter. OK. I still hesitate that /o really doesn't matter, because I still expect that a test needs to be done to find out if the variable has changed or not, but even with such a (fast) test it can hardly matter. >> If possible, I would like the modifiers to be in $re{'key'}[MODS]. >> (yes, this is all totally untested code yet) > > s/(?$re{key}[MODS])$re{key}[SRCH]/$re{key}[REPL]/ > > ought to do the trick. Ah, nice. Just another thing that I had read about but hadn't used yet. -- Affijn, Ruud "Gewoon is een tijger."
From: Abigail on 4 Nov 2005 03:07 Dr.Ruud (rvtol+news(a)isolution.nl) wrote on MMMMCDXLVIII September MCMXCIII in <URL:news:dkeo51.18o.1(a)news.isolution.nl>: ~~ Abigail: ~~ > Ruud: ~~ ~~ > does "$re{A01}[SRCH]" change? ~~ ~~ No, it's a constant. ~~ ~~ ~~ > If the first ~~ > question is answered with 'no', then using /o doesn't matter. ~~ ~~ OK. I still hesitate that /o really doesn't matter, because I still ~~ expect that a test needs to be done to find out if the variable has ~~ changed or not, but even with such a (fast) test it can hardly matter. It doesn't actually check whether a variable has changed - it just tests whether, after interpolation, the regex has changed. And compared to actually executing a regex, this test takes insignificant time. It doesn't weight up against the hard to trace bugs if the variable does change and the regex doesn't because you used /o. Abigail -- use lib sub {($\) = split /\./ => pop; print $"}; eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
From: Dr.Ruud on 4 Nov 2005 07:52 Abigail schreef: > [regex without /o] > It doesn't actually check whether a variable has changed - it just > tests whether, after interpolation, the regex has changed. And > compared to actually executing a regex, this test takes insignificant > time. It doesn't weight up against the hard to trace bugs if the > variable does change and the regex doesn't because you used /o. OK, thanks for confirming that. My /o's meant that the variables will never change after setup. Is there an efficient way to use constants in regexes? Maybe not useful when constants are actually subs. -- Affijn, Ruud (flip-flop) "Gewoon is een tijger."
From: John Bokma on 4 Nov 2005 10:05 "Dr.Ruud" <rvtol+news(a)isolution.nl> wrote: > Is there an efficient way to use constants in regexes? Maybe not useful > when constants are actually subs. using qr//? "Since Perl may compile the pattern at the moment of execution of qr() operator, using qr() may have speed advantages in some situations, notably if the result of qr() is used standalone:" (perlop) -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-)
From: Dr.Ruud on 4 Nov 2005 12:22
John Bokma: > Dr.Ruud: >> Is there an efficient way to use constants in regexes? Maybe not >> useful when constants are actually subs. > > using qr//? > > "Since Perl may compile the pattern at the moment of execution of qr() > operator, using qr() may have speed advantages in some situations, > notably if the result of qr() is used standalone:" > > {perlop) Thanks John. Abigail already mentioned it, but I didn't look into it right away and then I just didn't, so now at last I did. $re{'A01'}[SRCH] = 'some regex, grouping allowed'; $re{'A01')[REPL] = 'some replacement, backtracking allowed'; $re{'A01'}[MODS] = 'xsg'; : : $re{'A01'}[QREX] = qr/(?$re{'A01'}[MODS])$re{'A01'}[SRCH]/; # qompiled regex : : s/$re{'A01'}[QREX]/$re{'A01')[REPL]/; -- Affijn, Ruud "Gewoon is een tijger." |