in reply to Re^3: loop through values in a string and print " " around each value.
in thread loop through values in a string and print " " around each value.
$ perl -e' -> @l = (1, 2, 3); -> print @l, qq{\n}; -> print qq{@l\n}; -> $" = q{,}; -> print qq{@l\n};' 123 1 2 3 1,2,3 $
Note that printing the array outside quotes just concatenates the elements together whereas inside quotes separates them with the default space and once we change the default to a comma, voila.
In your particular case you also want to quote each field, which you can do in a map. We can create a new list to print, like this
use strict; use warnings; my @flds = qw{Leesville TX 23432 67867 88 Bloggs F}; my @quotedFlds = map { qq{"$_"} } @flds; { local $" = q{,}; print qq{@quotedFlds\n}; }
Note that I localise the change to $" in a small code block to avoid unexpected side-effects later in the script; localising changes like this is always good policy. Here's the output
"Leesville","TX","23432","67867","88","Bloggs","F"
I hope this is of use.
Cheers,
JohnGG
|
|---|