Andy,

You need to put the CSV file handling to binary mode.
Note, though, when I did, I had to add code to break
out of the loop as the while always returned true.
This code works as you desire, I believe.

hth,
--rich

#!/usr/bin/perl
use IO::File;
use Text::CSV_XS;

$csv = Text::CSV_XS->new({'binary' => 1});     # modified line for binary flag

no warnings;
$fullpathfile = "testfile.csv";

$io = new IO::File "< $fullpathfile";
if (not defined $io) {
    die "can't open $fullpathfile";
}

LOOP: while ($columns = $csv->getline($io)) {  # modified line for EOF ctrl
  last LOOP if @$columns == 0;                 # added line for EOF ctrl
  $csv->combine(@$columns);
  print $csv->string, "\n";"$columns\n";


}
close($io);
exit 0;


--- Andy Ryan <[EMAIL PROTECTED]> wrote:
> Well, I've tried both the ParseWords method and the CSV_XS method to no
> avail. Below is my CSV_XS script, along with a snippet from the csv
> file. If you run this through the script, it fails at the second line,
> where the umlaut is located. It's all very strange.
> 
> --- Begin Script ---
> #!/usr/bin/perl
> use IO::File;
> use Text::CSV_XS;
> 
> $csv = Text::CSV_XS->new();
> 
> no warnings;
> $fullpathfile = "testfile.csv";
> 
> $io = new IO::File "< $fullpathfile";
> if (not defined $io) {
>       die "can't open $fullpathfile";
> }
> 
> while ($columns = $csv->getline($io)) {
>   $csv->combine(@$columns);
>   print $csv->string, "\n";"$columns\n";
> 
>   
> }
> close($io);
> exit 0;
> 
> --- End Script ---
> --- Begin CSV File ---
> 10.10.10.0/24,DE,DE-Ravensburg,"Ravensburg EY, Germany"
> 10.10.10.0/24,DE,DE-Saarbruecken,"Saarbrüecken EY, Germany"
> 10.10.10.0/24,DE,DE-Singen,"Singen EY, Germany"
> --- End CSV File ----
> 
> -----Original Message-----
> From: Lynn. Rickards [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, November 25, 2003 4:22 PM
> To: 'Andy Ryan'
> Subject: RE: [Perl-unix-users] ParseWords and umlaut
> 
> I use Text::CSV myself withn no problem, but tried this:
> 
> foreach my $line(<F>)
>         {
>         my @words = &quotewords(",", "0", $line);
>         foreach (@words) {
>                 print "<$_>\n";
>                 }
>         print $line . "\n";
>         $c++;
>         last if($c == 12);
>         }
> 
> ...and inserting a few O and e into a csv.
> 
> Prints all lines and fields.
> 
> I can't even remember why, but to overcome a particular 
> problem I had with some particular data at
> some time, I did 
> $line = qq{$line};
> ..which kept whatever funny stuff was in there....
> 
> No help there unless you care to share a little
> test data?
> 
> -Lynn.
> 
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] 
> > Behalf Of Andy
> > Ryan
> > Sent: Tuesday, November 25, 2003 3:04 PM
> > To: [EMAIL PROTECTED]
> > Subject: [Perl-unix-users] ParseWords and umlaut
> > 
> > 
> > Hi folks,
> > 
> > I'm using the ParseWords perl module to parse through a csv file. When
> > it encounters a word in it, specifically one with an umlaut in it, it
> > creates an empty set for that line in the file. Any suggestions on how
> > to fix this?
> > 
> > Thanks.
> > 
> > 
> > _______________________________________________
> > Perl-Unix-Users mailing list
> > [EMAIL PROTECTED]
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> > 
> 
> 
> 
> _______________________________________________
> Perl-Unix-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to