I am trying to download a .csv file into an array and then parse each column line-by-line with Text::CSV. I have the following:
my @file = get("http://www.someCSV.com/file.csv") or warn $!;
my $CSV = Text::CSV->new();
$CSV->sep_char (',');
for ( @file ) {
$CSV->parse($_) or warn $!;
my @columns = $CSV->fields();
print $columns[0] . "\n";
}
Rather than downloading the file, saving it and then slurping it into a filehandle, I thought it would be more efficient to just put the CSV file into an array and parse from there. However, the above code doesn't work and I don't understand why. I get "Warning: something's wrong at test.pl"; not very helpful, to say the least.
This is more for learning. I don't have to do it this way but it's just bugging me why I'm not able to use Text::CSV with an array.