GertMT has asked for the wisdom of the Perl Monks concerning the following question:

dear Monks,

While reading a csv-file I've had some trouble using Text::CSV_XS for a reason that might have to do with eol (re. my post from y'day where Tux and ELISHEVA give me valuable info). That's why I'm trying to use Text::ParseWords but I just can't get to the final stage and was wondering if someone could help me.

I know that there's a lot of 'fields' as I counted them. While trying to print them in an orderly way I get all of them (not orderly and commented out) or just the value of the elements from the first line.

The last line of code obviously doesn't make sense. The fields should be coming from 'every single line', (@lines? and not @fields?)

Needless to say I'm not able to use the defined variables.
What am I doing wrong?

I did check some docs on refences and so but all is a bit confusing now.

thanks, Gert
#!/usr/bin/perl use warnings; use strict; use diagnostics; use Text::ParseWords; my $csvfilename = "data.csv"; open( FILE, "<$csvfilename" ) or die("Couldn't open CSV file $csvfilename:$!\\n"); # Read lines from STDIN. my $line = (); my @fields = (); my $field = (); while ( $line = <FILE> ) { @fields = &quotewords( ',', 0, $line ) or ( warn "problem on line $.:$_" ); # Set variable values based on the array values. my $id = $fields[0]; my $brand = $fields[1]; my $dbt = $fields[2]; my $cdt = $fields[3]; my $color = $fields[4]; my $number = $fields[5]; # print "@fields\n"; my $arraySize = $#fields + 1; print "array size = $arraySize\n"; print "array size = ", @fields . "\n"; print __LINE__ + 1 . ": I'm in trouble here...\n"; foreach $line (@fields) { print "$fields[0]\t$fields[1]\n"; } }