Esteemed Monks,
Consider the following code, input file, and output:
#!/usr/local/bin/perl use strict; use Text::CSV_XS; use FileHandle; my $infile = "foo.csv"; my $IN = new FileHandle; open ( $IN, "<$infile") or die "can't read $infile: $!"; my $c = 0; my $csv = Text::CSV_XS->new( {'binary' => 1}); while ( my $cols_aref = $csv->getline( $IN ) ) { my @a = @{$cols_aref}; print "$a[0],$a[1],$a[2]\n"; $c++; # Alternative way to assure exiting loop exit if ( $c > 5 ); } exit; ## My foo.csv Fred,foo,3 Tom,bar,4 ## Output: Fred,foo,3 Tom,bar,4 ,, ,, ,, ,,
I don't understand what's happening in the while condition that prevents it from ending when it reaches EOF. Can anyone educate me?
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday
In reply to Concerning Text::CSV_XS getline in while loop by freddo411
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |