Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Answer: How do I insert, (not overwrite) into a string?

( #29253=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How do I insert, (not overwrite) into a string? contributed by KM

Did a quick benchmark out of curiosity:

KM:     substr($_,0,0,"H")
Ovid:    s/^(.*)$/H$1/
Shendal:  $_ .= "H".$_
turnstep: s/^/H/

Benchmark: timing 100000 iterations of KM, Ovid, Shendal, turnstep... KM: -1 wallclock secs ( 0.55 usr + 0.00 sys = 0.55 CPU) Ovid: 2 wallclock secs ( 2.20 usr + 0.00 sys = 2.20 CPU) Shendal: 0 wallclock secs ( 0.53 usr + 0.00 sys = 0.53 CPU) turnstep: 1 wallclock secs ( 0.98 usr + 0.00 sys = 0.98 CPU)

Cheers,
KM

Comment on Answer: How do I insert, (not overwrite) into a string?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-09-17 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (57 votes), past polls