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

tiger peng tigerpeng2001 at yahoo.com
Sat Dec 15 17:46:44 PST 2007


check this:
http://en.wikipedia.org/wiki/Newline
How did you get .cvs? How did you rename it to .txt?

----- Original Message ----
From: Eric Ellington <e.ellington at gmail.com>
To: Chicago.pm chatter <chicago-talk at pm.org>
Sent: Saturday, December 15, 2007 11:47:20 AM
Subject: Re: [Chicago-talk] Why does Perl hate my csv file?


I don't follow. I thought $/ was newline by default and I thought
newline was a carriage return. Am I wrong? Why does my problem go away
if I name all my files with a .txt extension?

On Dec 13, 2007 10:32 PM, tiger peng <tigerpeng2001 at yahoo.com> wrote:
>
> it seems that all line end with carriage return character (ascii
 octal num
> 15) only. There is no line feed (newline character in Unix)
>
> I made one in Linux and you can see the difference:
>
> gpeng at linbay:/home/gpeng/perl
> -> perl  -ne 'print $_' 2.csv
>
> WLANE_02,51,3.2,55,60,32,19,0,0,17.6,17.1,11/1/2007,0:00:00,,
> gpeng at linbay:/home/gpeng/perl
> -> perl  -ne 'print $_,"\n"' 2.csv
>
> WLANE_02,51,3.2,55,60,32,19,0,0,17.6,17.1,11/1/2007,0:00:00,,
>
> gpeng at linbay:/home/gpeng/perl
> -> perl -015  -ne 'print $_,"\n"' 2.csv  # use carriage character as
> recorder separator
>
> 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,,
>
>
> gpeng at linbay:/home/gpeng/perl
>
>
>
>
>
> ----- Original Message ----
> From: Eric Ellington <e.ellington at gmail.com>
> To: Chicago.pm chatter <chicago-talk at pm.org>
> Sent: Thursday, December 13, 2007 10:07:50 PM
> Subject: Re: [Chicago-talk] Why does Perl hate my csv file?
>
>  I am creating everything on a windows system. I checked the line
> endings and they look OK to me. Like I said the file works with any
> other extension besides csv. Giving it .123 worked.
>
> The output is jacked up in the windows cmd terminal, all of the
 output
> is printed on the same line. I can watch it overwrite it self and
 then
> I just get some data smashed
> onto one line.
>
> Cut and Pasted:
> ,,,,,,,,,,,,1,42,44,2,0,0,0,450,449.7,12/1/2007,3:00:0000
>
> This is a scaled down version of something larger. However, I am
> having the exact same problem with the code I posted and I am just
> testing with a different file which I attached to this email. If
 there
> are any weird characters I am not sure what they are or how they are
> messing things up. I see nothing but CR's on every line and one LF on
> the final line.
>
> I also turned on use warnings but got no warnings.
>
> On Dec 13, 2007 6:49 PM, Andy Lester <andy at petdance.com> wrote:
> >
> > On Dec 13, 2007, at 6:46 PM, Eric Ellington wrote:
> >
> > > 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.
> >
> >
> > No, Perl doesn't care at all.  There's something else going on that
> > you're not describing.  Are the line-endings different for your
> > machine from the machine that you got the file from?  You're on
 Unix
> > and it came from Windows, or vice versa?
> >
> > Also, although "use strict" is a good thing, even more important is
> > "use warnings".
> >
> > Throw that in and see what else happens.  And what does "the output
 is
>
> > jacked up" mean, anyway?
> >
> > xoox,
> > Andy
> >
> > --
> > Andy Lester => andy at petdance.com => www.petdance.com =>
 AIM:petdance
> >
> >
> >
> >
> > _______________________________________________
> > Chicago-talk mailing list
> > Chicago-talk at pm.org
> > http://mail.pm.org/mailman/listinfo/chicago-talk
> >
>
>
>
> --
>
> Eric Ellington
> e.ellington at gmail.com
>
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>



-- 
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/20071215/44f133c5/attachment.html 


More information about the Chicago-talk mailing list