perl - Print hash of arrays with commas between the elements of the array -
i using
$fields ( sort {$a<=>$b} keys %hoa) { print "$fields-->@{$hoa{$fields}}\n"; } to print hash. output is:
0-->2132123 321321321 abcdefg 32 def ... i like:
0-->2132123,321321321,abcdefg,32,def,... is there way alter print statement give me commas? rather not use s/ /,/.
use explicit join.
for $fields ( sort {$a<=>$b} keys %hoa) { print "$fields-->" . join (',', @{$hoa{$fields}}) . "\n"; } or localize version of $list_separator per perlvar
for $fields ( sort {$a<=>$b} keys %hoa) { local $" = ','; print "$fields-->@{$hoa{$fields}}\n"; }
Comments
Post a Comment