I want to output the elements of an array in a specific format in Perl.
@myArray = ("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("\" \"", @myArray) . "\"";
if ($text eq "\"\"")
{
$text = "";
}
Which I think would work. However, is there a more elegant way to do this?