A small variation on some other approaches, and has the drawback of needing state (introduced with 5.10), and I'm not going to benchmark it, but...
c:\@Work\Perl\monks>perl -wMstrict -le "use feature 'state'; ;; my $s = '1 {\d1} 2 {\d2} xx{\d3}yy'; print qq{'$s'}; ;; $s =~ s{ \{ \\d (\d+) \} }{ ran_digs($1) }xmsge; print qq{'$s'}; ;; sub ran_digs { state $powers = { map { $_ => 10 ** $_ } 1 .. 7 }; ;; return int rand $powers->{$_[0]}; } " '1 {\d1} 2 {\d2} xx{\d3}yy' '1 7 2 18 xx406yy'
In reply to Re: Speed Improvement
by AnomalousMonk
in thread Speed Improvement
by Nar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |