Concat a String
Scott Penrose
scottp at dd.com.au
Tue Nov 26 00:20:16 CST 2002
Hey Dudes,
I find that we have a lot of code that loops through code continually
building a XML object or some HTML or some other type of string by
continuing to concatenate a string.
eg:
foreach my $x (@y) {
$out .= $x->{something} . "\n";
}
(the example above is too trivial to be real, coz you could just use a
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);
Or we could even go a lot further and do it without temporary variables.
$out = join("\n",
map {
$_->{something}
} @y
);
(oooh I am looking forward to Perl 6, where I don't have to use $_ for
the map above :-)
Which is more efficient but still logical to read ?
Also if I go about the join/map code above, do you think it is
reasonable to have a very complicated MAP method, or is that just too
hard to read/understand ?
Scott
--
Scott Penrose
Anthropomorphic Personification Expert
http://search.cpan.org/search?author=SCOTT
scott at cpan.org
Dismaimer: While every attempt has been made to make sure that this
email only contains zeros and ones, there has been no effort made to
guarantee the quantity or the order.
More information about the Melbourne-pm
mailing list