need help to find the built-in Perl module

chronodekar

Senior member
Nov 2, 2008
721
1
0
My googling skills just don't seem to be up to the task. I KNOW there is a built-in module in Perl that will make it easy to read information from a comma-separated values (csv) file, but I just can't seem to find it.

I gave up last month and started doing the job manually, but my csv file is getting bigger, and I NEED to know the name of the built-in Perl module which does this.

Help ?
 

chronodekar

Senior member
Nov 2, 2008
721
1
0
Hmmm.... that looks interesting. I'll report back how well it runs.

And about CPAN, well, perhaps it's just that I haven't put in that much effort, but I don't understand the layout of that site. Then again, I just use Perl as "get job done fast" language. I don't spend too much time with it. I think you've convinced me to re-think that opinion.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
CPAN is part of getting stuff done fast. It's basically a collection of scripts other people have used to get things done fast, meaning very often a large portion of your problem has a solution on there already.

BTW, the DBD::CSV package is really meant for treating a CSV file like an SQL database (with SQL queries and such). If you just want CSV parsing (and you don't know SQL), you might want to try another package. For example,

http://search.cpan.org/~danboo.../lib/Tie/Handle/CSV.pm

Or just search http://search.cpan.org/ for "CSV" and see what shows up.
 

Onund

Senior member
Jul 19, 2007
287
0
0
really? perl makes it easy to read csv files....

open($handle, "<file.csv")
while(<$handle>) {
my @parts = split /,/;
...
}

how is the problem tedious/hard? Is the cvs file format/order changing and you need a way to get consistent results?
 

chronodekar

Senior member
Nov 2, 2008
721
1
0
Thanks for all the help guys. In the end, CPAN along with some googling helped. This is what I found useful,

http://search.cpan.org/~alancitt/Text-CSV-0.01/CSV.pm

It took me a while to get it installed on my XP system, but it seems to be working fine now. I've not stress-tested it yet, but hopefully, it'll stand it.

Onund, originally I used my own way to parse csv files, but my csv files are generated by MS Excel 2003 and OpenOffice.Org so, I had to move on to relying on some else's hard work of sorting out the different combination of csc files. ;)

 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
how is the problem tedious/hard? Is the cvs file format/order changing and you need a way to get consistent results?

Trust me, once you have a CSV file with things like company names that contain commas and other special characters you'll realize it's not as easy as just using split.
 

Onund

Senior member
Jul 19, 2007
287
0
0
Originally posted by: Nothinman
how is the problem tedious/hard? Is the cvs file format/order changing and you need a way to get consistent results?

Trust me, once you have a CSV file with things like company names that contain commas and other special characters you'll realize it's not as easy as just using split.

That was my question, I was looking for more background in the specific problem. didn't mean to make it sound like it's an easy task, it that's how it came across.

to say "make it easy to read cvs files" is pretty open ended. My code snippet makes it easy to read cvs files. There must have been something specific the OP wanted the cvs parser to do. I looked at the linked packages and I still don't necessarily understand why I would use one of those over hand coding it. But the OP had something in mind and one of those works so that's good.

oh, and by definition, cvs is just as easy as split. If there is a company name with commas then that is not a good candidate for a cvs file, IMO.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
oh, and by definition, cvs is just as easy as split. If there is a company name with commas then that is not a good candidate for a cvs file, IMO.

But commas are valid inside a column in a CSV, they just have to be specially handled. Although I believe most of the modules on CPAN don't take that into account either so when I did that I ended up writing my own parser.
 

chronodekar

Senior member
Nov 2, 2008
721
1
0
Hmmm... :eek:

I first used Excel 2003 to generate my cvs files. Initially all it did was separate the values by commas. So, that was not too difficult to parse. At one point, I tried using OpenOffice3 and that used double-quotes to "contain" the data. I had to abandon it soon after as, not too many locations I program have OpenOffice3 installed.

Recently, for some reason, Excel also began to use double-quotes (at random locations!). At first, I thought my Perl script was mis-behaving, but on investigating, I found that it was the csv file that was causing problems.

At that point, I wasn't really in a good mood to sit and write down a csv parser,I was more interested in getting the job done, so I decided to go searching around for a module. And that is how I ended up here. ;)

On reflection, considering how much effort I put in, to figuring out (or trying to recall) how to install Perl modules in XP, I suppose I could have just written a parser myself. Like I mentioned, I've not stress-tested the module yet, so I might end up doing that anyway.

I hope my explanation is satisfactory guys? (to Onund & Nothinman)

EDIT: If anyone is STILL curious, I use Perl to generate the second post at this thread. I store all the links in a csv file and edit it with excel. :)