[Chicago-talk] Why does Perl hate my csv file?

Eric Ellington e.ellington at gmail.com
Thu Dec 13 16:46:26 PST 2007


Using this script:

use strict;

main();

sub main
{
	open(FILE,"1.csv") || die "COULD NOT OPEN FILE: \n$!\n";
	#nix header
	my $x = <FILE>;
	while (<FILE>)
	{
		print $_;
	}
}

where 1.csv contains:
Header
RLANE_02,16,0.6,54,58,16,0,0,0,56.3,55.9,11/1/2007,0:00:00,,
RLANE_01,8,0.3,56,59,8,0,0,0,112.5,112.2,11/1/2007,0:00:00,,
ELANE_02,60,3.9,56,61,32,28,0,0,15,14.4,11/1/2007,0:00:00,,
ELANE_01,23,1.3,60,65,13,10,0,0,39.1,38.6,11/1/2007,0:00:00,,
WLANE_01,10,0.3,57,58,9,1,0,0,90,89.7,11/1/2007,0:00:00,,
WLANE_02,51,3.2,55,60,32,19,0,0,17.6,17.1,11/1/2007,0:00:00,,
,,,,,,,,,,,,,,

I get no output.

Change the file name to 1.txt and I get output or if I comment out "my
$x = <FILE>;" and even then the output is jacked up. Why is that? Does
open do something special when it sees a file that ends in .csv? I
found nothing at http://perldoc.perl.org/functions/open.html or on
ActiveState's website.

This is perl, v5.8.8 built for MSWin32-x86-multi-thread on windows XP.

-- 
Eric Ellington
e.ellington at gmail.com


More information about the Chicago-talk mailing list