Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 musing on the Monastery: (8)
As of 2014-08-21 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (141 votes), past polls