Concat a String

Peter G. Martin peterm at
Tue Nov 26 23:45:52 CST 2002

Scott Penrose:
On Tue, 26 Nov 2002 17:20:16 +1100,  you wrote:
>Hey Dudes,
>I find that we have a lot of code that loops through code
>building a XML object or some HTML or some other type of string by
>continuing to concatenate a string.
>    foreach my $x (@y) {
>        $out .= $x->{something} . "\n";
>    }
>(the example above is too trivial to be real, coz you could just use
>map there !)
>Anyway I was wondering if we should be doing something much more
>sensible, along the lines of
>    foreach my $x (@y) {
>        push @z, $x->{something};
>    }
>    $out = join("\n", @z);

Maybe have a look at Data::Locations, which can go further, and 
collect elements in all kinds of different places.   Advantages include being able to 
use ties, print, printf, etc etc.     But more particularly, it's a bit easier
to hand non-sequential data that can assembled in bits and then pulled together
in your own order at the end of processing.

Peter G. Martin, peterm at on 27/11/2002

More information about the Melbourne-pm mailing list