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

Re: Is there something faster than string concatenation?

by hossman (Prior)
on Dec 10, 2007 at 02:45 UTC ( #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
Node Status?
node history
Node Type: note [id://656036]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2020-07-09 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?