Siegfried Heintze wrote:
I'm writing perl cgi and I like to buffer my output in an array of strings.
I just decided it would be very useful to be able to have nested arrays.
Below is a little function that does what a want. However,
(1) Is there a more compact way of performing this nested concatenation?
(2) Hasn't someone else already written a function like this that is
part of the standard repertoire?
(3) Assuming I have to use my own function below: My code only
concatenates the elements first argument. How can I concatenate all the
elements of all the function arguments?
(4) Is it possible to have nested lists? How would I modify my code to
handle those?
use strict;
use warnings;
sub concat {
my $sResult = shift;
return join("", map { ref($_) eq "ARRAY"? concat($_) :"$_ " }
@{$sResult});
}
print concat (["hello ", "there", ["a", "nested", "array"], "world!"]);
Is this what you want?
$ perl -le'
sub concat { return join " ", map ref eq "ARRAY" ? concat( @$_ ) : $_, @_ }
print concat( [ "hello ", "there", [ "a", "nested", "array" ], "world!" ] );
'
hello there a nested array world!
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>