freddo411 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Concerning Text::CSV_XS getline in while loop
by jZed (Prior) on Dec 21, 2004 at 21:53 UTC | |
by freddo411 (Chaplain) on Dec 21, 2004 at 22:45 UTC | |
by Anonymous Monk on Feb 27, 2010 at 16:38 UTC | |
by Tux (Canon) on Feb 28, 2010 at 10:12 UTC |