boom has asked for the wisdom of the Perl Monks concerning the following question:
I want to output the elements of an array in a specific format in Perl.
my @Array = ("A", "B", "C");
$text = something;
Something should be the string '"A" "B" "C"' (each element enclosed in double quotes).
However, if @myArray is empty, then $text should be too. I thought of using join(), such as
$text = "\"" . join("\" \"", @Array) . "\"";
if ($text eq "\"\"")
{
$text = "";
}
Which I think would work. However, is there a more elegant way to do this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I output each Perl array element sourrounded in quotes?
by AnomalousMonk (Archbishop) on Apr 18, 2009 at 21:05 UTC | |
|
Re: How do I output each Perl array element sourrounded in quotes?
by Anonymous Monk on Apr 18, 2009 at 13:20 UTC | |
by almut (Canon) on Apr 18, 2009 at 13:25 UTC | |
by CountZero (Bishop) on Apr 18, 2009 at 17:48 UTC | |
by AnomalousMonk (Archbishop) on Apr 18, 2009 at 21:32 UTC |