I am trying to print all array values ββfrom a CSV file. I kind of manually do this in the example below. Can someone show me the code for this for all the fields of the array no matter how many fields there are? I'm just trying to print each field on a new line.
#!/usr/bin/perl use strict; use warnings; use Text::CSV_XS; my $file = 'test.csv'; my $csv = Text::CSV_XS->new ({ quote_char => '"', escape_char => '@', binary => 1, keep_meta_info => 0, allow_loose_quotes => 1, allow_whitespace => 1, }); open (CSV, "<", $file) or die $!; while (<CSV>) { if ($csv->parse($_)) { my @columns = $csv->fields(); print "$columns[0]\r\n"; print "$columns[1]\r\n"; print "$columns[2]\r\n"; print "$columns[3]\r\n"; print "$columns[4]\r\n"; print "$columns[5]\r\n"; print "$columns[6]\r\n"; print "$columns[7]\r\n"; } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } } close CSV;
perl csv
Xl.
source share