For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2006 > Read a comma delimited text file (csv)









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 Read a comma delimited text file (csv)
jacsilva@aol.com

2006-09-06, 6:57 pm

I have a comma delimited text file and I want to read it line by line
and anything that is a string/char needs quotes placed around it. In
addition everything should be written to a txt file. What is the best
way to do this?

For example data in the file currently looks like:
ISP_KuSA1_Forward,1,FNC,Forward

Ouput should be:
"ISP_KuSA1_Forward",1,"FNC","Forward"

Thanks in advance

usenet@DavidFilmer.com

2006-09-06, 6:57 pm

jacsi...@aol.com wrote:
> I have a comma delimited text file and I want to read it line by line


CPAN has lots of CSV modules. Are you saying that NONE of these do what
you want?

--
David Filmer (http://DavidFilmer.com)

Paul Lalli

2006-09-06, 6:57 pm

jacsi...@aol.com wrote:
> I have a comma delimited text file and I want to read it line by line
> and anything that is a string/char needs quotes placed around it. In
> addition everything should be written to a txt file. What is the best
> way to do this?


Probably by using a module specifically designed for processing your
kind of data. What did you find when you went to
http://search.cpan.org and searched for "CSV"?

Paul Lalli

jacsilva@aol.com

2006-09-06, 6:57 pm


Paul Lalli wrote:
> jacsi...@aol.com wrote:
>
> Probably by using a module specifically designed for processing your
> kind of data. What did you find when you went to
> http://search.cpan.org and searched for "CSV"?
>
> Paul Lalli


I found a lot of information...I just not sure which one fits my case.

usenet@DavidFilmer.com

2006-09-06, 6:57 pm

jacsi...@aol.com wrote:
> I found a lot of information...I just not sure which one fits my case.


But you are the only person qualified to make that determination... you
are the only person who fully understands your requirements.

--
David Filmer (http://DavidFilmer.com)

jacsilva@aol.com

2006-09-06, 6:57 pm


usenet@DavidFilmer.com wrote:
> jacsi...@aol.com wrote:
>
> But you are the only person qualified to make that determination... you
> are the only person who fully understands your requirements.
>
> --
> David Filmer (http://DavidFilmer.com)


This is what I have so far...not much

my $parser = Parse::CSV->new(
file => 'All_command_Sequences.csv',
);

while ( my $value = $parser->fetch ) {
# if [A-Za-z] put quotes around it and write it to a file

}

jacsilva@aol.com

2006-09-06, 6:57 pm


usenet@DavidFilmer.com wrote:
> jacsi...@aol.com wrote:
>
> But you are the only person qualified to make that determination... you
> are the only person who fully understands your requirements.
>
> --
> David Filmer (http://DavidFilmer.com)


This is what I have so far...not much

my $parser = Parse::CSV->new(
file => 'All_command_Sequences.csv',
);

while ( my $value = $parser->fetch ) {
# if [A-Za-z] put quotes around it and write it to a file

}

usenet@DavidFilmer.com

2006-09-06, 6:57 pm

jacsi...@aol.com wrote:
> This is what I have so far...not much


> [snip code]


It looks like a good start.

--
David Filmer (http://DavidFilmer.com)

Sponsored Links







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

Copyright 2008 codecomments.com