Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Is there something faster than string concatenation?

by hossman (Prior)
on Dec 10, 2007 at 02:45 UTC ( [id://656036]=note: print w/replies, xml ) Need Help??


in reply to Is there something faster than string concatenation?

If it helps to wrap your mind around it, think of perl "strings" as java StringBuffers. For this perl code...
my $output = ""; for (1 .. 1000) { $output .= get_long_string(); } print $output;
...the analogous java code is...
StringBuffer output = new StringBuffer(); for (1 .. 1000) { output.appends(get_long_string()); } System.out.print(output.toString());
I would not be surprised however if this perl code behaved as inefficiently as you might expect it to...
my $output = ""; for (1 .. 1000) { $output = "" . get_long_string() . $output; } print $output;
(but i haven't tested it ... perl might optimize it)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-16 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found