For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > CVS_XS Module









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author CVS_XS Module
Itzik Brown

2006-01-28, 3:55 am

HI ,
I tried to create a csv file like this:

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

my $csv =3D Text::CSV_XS->new();
my $fd =3D new IO::File;
open $fd,">","out.csv" or die "can't open file for writing\n";

my @cols =3D ('cow','dog','bar');
$csv->print($fd,\@cols);
@cols =3D ('1','2','bar');
$csv->print($fd,\@cols);

close $fd;

My Question:
How Do i put new lines between the lines in the csv files?

tnx
Xavier Noria

2006-01-28, 6:56 pm

On Jan 28, 2006, at 9:06, itzik brown wrote:

> #!/usr/bin/perl -w
> use strict;
> use Text::CSV_XS;
> use IO::File;
>
> my $csv = Text::CSV_XS->new();
> my $fd = new IO::File;
> open $fd,">","out.csv" or die "can't open file for writing\n";
>
> my @cols = ('cow','dog','bar');
> $csv->print($fd,\@cols);
> @cols = ('1','2','bar');
> $csv->print($fd,\@cols);
>
> close $fd;
>
> My Question:
> How Do i put new lines between the lines in the csv files?


Reading both the docs (which are not very clear in this regard) and
the source code, the solution within the module API is:

my $csv = Text::CSV_XS->new({ eol => "\n" });

-- fxn

Chas Owens

2006-01-28, 6:56 pm

$fd is a normal file handle, just print to it.

On 1/28/06, itzik brown <gandalf100@gmail.com> wrote:
> HI ,
> I tried to create a csv file like this:
>
> #!/usr/bin/perl -w
> use strict;
> use Text::CSV_XS;
> use IO::File;
>
> my $csv =3D Text::CSV_XS->new();
> my $fd =3D new IO::File;
> open $fd,">","out.csv" or die "can't open file for writing\n";
>
> my @cols =3D ('cow','dog','bar');
> $csv->print($fd,\@cols);


print $fd, "\n";

> @cols =3D ('1','2','bar');
> $csv->print($fd,\@cols);
>
> close $fd;
>
> My Question:
> How Do i put new lines between the lines in the csv files?
>
> tnx
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>

gandalf100@gmail.com

2006-01-28, 6:56 pm

Tnx,
i'll better know how to read the manual next time.
BTW print to $fd raised 2 errors(i did it before i asked..)


cya


Xavier Noria =D7=9B=D7=AA=D7=91:
> On Jan 28, 2006, at 9:06, itzik brown wrote:
>
>
> Reading both the docs (which are not very clear in this regard) and
> the source code, the solution within the module API is:
>=20
> my $csv =3D Text::CSV_XS->new({ eol =3D> "\n" });
>=20
> -- fxn


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com