in reply to Re: Precompiling substitution regex
in thread Precompiling substitution regex

FWIW, note that in the second example here, the outer for-loop is not needed:

c:\@Work\Perl\monks>perl -wMstrict -le "my @re_subs = ( sub { s/(?:this|or|that)/bob/gsi for @_ }, sub { s/(?:One|Two|Three)/Four/gs for @_ }, ); ;; my @strings = ('tHiS one or ThAt other', 'One two Three'); printf qq{'$_' } for @strings; print ''; ;; $_->(@strings) for @re_subs; printf qq{'$_' } for @strings; print ''; " 'tHiS one or ThAt other' 'One two Three' 'bob one bob bob other' 'Four two Four'
That's because of aliasing through the  @_ function argument array. Actually, the work of the outer for-loop is just being moved to the for-loop within each anonymous subroutine, which is now given something to loop over whereas before it was just being used for topicalization.


Give a man a fish:  <%-{-{-{-<