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

tiger peng tigerpeng2001 at yahoo.com
Thu Dec 13 20:15:35 PST 2007


It seems that your $x=<FILE> consumed the whole file.
Is there newline character "\n" in your 1.csv file?How did you invoke the script?  How did you change the file name? Is the size of file changed after you change the name?

----- Original Message ----
From: Eric Ellington <e.ellington at gmail.com>
To: Chicago.pm chatter <chicago-talk at pm.org>
Sent: Thursday, December 13, 2007 6:46:26 PM
Subject: [Chicago-talk] Why does Perl hate my csv file?


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
_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20071213/2bff42c6/attachment.html 


More information about the Chicago-talk mailing list