Forum Moderators: coopster & phranque

Message Too Old, No Replies

Script to read from CSV or tab-delimited file

have a working script, looking for something more robust

         

Slud

6:45 pm on Jul 17, 2003 (gmt 0)

10+ Year Member



Currently I'm using CSVRead [ezscripting.co.uk] to retrieve rows from a reasonably large (4000 row) tab-delimited file I have.

Performance is sufficient, but I'm looking for something more robust. My ideal script would have all the capabilities of Excel's autofilter (range search, match and negative match on same field, etc.)

Does anyone have a favorite script for this?

Josk

9:26 am on Jul 18, 2003 (gmt 0)

10+ Year Member



I would suggest Text::ParseWord (parse text into an array of tokens or array of arrays) and then build your own.

But do a search on CPAN (cpan.org) and theres a whole host of different methods to try. The most functional would probably by DBD:CSV... Treats a csv file as a database so you can use SQL on it.

But then its Perl. Its what it's good at...

Storyteller

7:01 pm on Jul 18, 2003 (gmt 0)

10+ Year Member



Slud, why not use a real DB, like MySQL for this? You can import CSV right into it with LOAD DATA command, and it's as fast as it gets.

Slud

6:38 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



Thanks for the good CPAN leads. I'm on shared hosting right now, so I don't know if I'll be able to install any modules, but I should definitely be able to find some good code to adapt.

Storyteller, I true DB would definitely be the prefered method, but the details of the multiple sites I'm running off my current "DB" make the management overhead of SQL unattractive.

dkubb

6:57 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



It doesn't matter if you're on shared hosting or not as long as you have shell access to the server (through SSH or Telnet). You don't need root to install perl modules either. You can install a perl module in a private directory, and tell your perl scripts to look in this directory for any modules you use.

Simply upload the perl module, untar/gzip it, and run the following from the directory thats created when you untar the module:

perl Makefile.PL PREFIX=/home/dkubb/lib
make test install

(Replace "/home/dkubb/lib" with your library directory)

Then in your perl scripts, add the following BEFORE you "use" any modules:

use lib qw(/home/dkubb/lib);

When the perl script runs it will look in this directory first when loading modules.

Slud

7:22 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



Thanks for the tip dkubb. I had no idea that was possible. That opens up a whole new world of code I can use. Rock!