Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Speed Improvement

by AnomalousMonk (Archbishop)
on Dec 01, 2014 at 22:13 UTC ( [id://1108891]=note: print w/replies, xml ) Need Help??


in reply to Speed Improvement

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'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1108891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2026-05-08 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.