Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing CSV files 2

Status
Not open for further replies.

stones1030

Programmer
May 30, 2006
15
US
Can anyone help me with this?
I am looking for any code/modules which will parse CSV files. I came across Text::CSV pm. Bu twhen I downloaded it, the readme file conatined instructions to install/setup on UNIX platform only.
I am loking for something on Windows 2000.
Thank you,
 
Are you using ActiveState perl on your Windows machine? Most people who have perl installed on a Windows machine use ActivePerl.

If so, go to your Windows Command prompt, and enter
ppm3
Here's what I did:
Code:
H:\>ppm3
PPM - Programmer's Package Manager version 3.1.
Copyright (c) 2001 ActiveState Corp. All Rights Reserved.
ActiveState is a devision of Sophos.

Entering interactive shell. Using Term::ReadLine::Stub as readline library.

Type 'help' to get started.

ppm> search Text-CSV
Searching in Active Repositories
  1. Text-CSV
  2. Text-CSV-DetectSeparator
  3. Text-CSV-Separator
  4. Text-CSV-Simple
  5. Text-CSV_PP
  6. Text-CSV_XS
ppm> install 1
Package 1:
====================
Install 'Text-CSV' version 0.01 in ActivePerl 5.8.4.810.
====================
Downloaded 5527 bytes.
Extracting 15/15: blib/arch/auto/Text/CSV/.exists
Installing C:\Perl\html\site\lib\Text\CSV.html
Installing C:\Perl\site\lib\auto\Text\CSV\autosplit.ix
Installing C:\Perl\site\lib\auto\Text\CSV\combine.al
Installing C:\Perl\site\lib\auto\Text\CSV\error_input.al
Installing C:\Perl\site\lib\auto\Text\CSV\fields.al
Installing C:\Perl\site\lib\auto\Text\CSV\new.al
Installing C:\Perl\site\lib\auto\Text\CSV\parse.al
Installing C:\Perl\site\lib\auto\Text\CSV\status.al
Installing C:\Perl\site\lib\auto\Text\CSV\string.al
Installing C:\Perl\site\lib\auto\Text\CSV\version.al
Installing C:\Perl\site\lib\auto\Text\CSV\_bite.al
Installing C:\Perl\site\lib\Text\CSV.pm
Successfully installed Text-CSV version 0.01 in ActivePerl 5.8.4.810.
ppm> quit

H:\>

That will install the module for you on your Windows machine.

So my commands were:
ppm3
search Text-CSV
install 1
quit

Pretty Easy!
 
Hi,
THIS IS REALLY URGENT. HELP APPRECIATED.

I was able to install the Text-CSV module on my desktop and laptop without any problem. Right now I am working on an installation guide for my script. And when I tried to repeat the installation of CSV module on another desktop, I did not get the same four options which I got for the first time. Only 2 options were displayed. And they were not numbered(as BrianAtWork) indicated above to choose an option.
What is causing this dynamic behaviour and how can I make sure that I can get the same options/behaviour somehow to document it to setup the environment?

Thanks in advance,
 
how about just "ppm3 install Text-CSV" from the command line. I think he had you use the shell to show you how to search for modules when you don't know the exact name. If you know specifically what the module is called, you can skip the ppm shell and install it directly.

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
icrf,
Thank you. That worked atleast on one desktop. Will it usually behave the same way? Please let me know if the command is dependant on the environment in any way.
THANKS AGAIN,
 
It has to do with the repositories that ppm is looking at.
You can view these, or change these with the "rep" command in the ppm3 shell.
You could set up the same repository at the top of everyone's list to make it consistent.
Code:
H:\>ppm3
PPM - Programmer's Package Manager version 3.1.
Copyright (c) 2001 ActiveState Corp. All Rights Reserved.
ActiveState is a devision of Sophos.

Entering interactive shell. Using Term::ReadLine::Stub as readline library.

Type 'help' to get started.

ppm> rep
Repositories:
[1] CTemp
[2] Cdrive
[3] cperl
[4] ActiveState PPM2 Repository
[ ] ActiveState Package Repository
[ ] Autonamed 1
[ ] Autonamed 2
As you can see, if I go to install a module using ppm, it will first look at my temp folder "alias CTemp", then a folder on my c drive "Cdrive", then in my perl folder on my c drive "cperl", and finally in the Active state repository.

Go into the ppm3 shell, and type "help rep" for commands you can do with the repository. It will show you how to move repositories up and down, add, rename, remove, enable, disable, etc...

Use the "rep describe n" where n is the number - for example, I ran this:

Code:
ppm> rep
Repositories:
[1] CTemp
[2] Cdrive
[3] cperl
[4] ActiveState PPM2 Repository
[ ] ActiveState Package Repository
[ ] Autonamed 1
[ ] Autonamed 2
ppm> rep describe 4
Describing Active Repository 4:
    Name: ActiveState PPM2 Repository
Location: [URL unfurl="true"]http://ppm.ActiveState.com/cgibin/PPM/ppmserver-5.8-windows.pl?urn:/PPMServer[/URL]
    Type: PPMServer 2.0
ppm>

You could add the same repository to the top of everyone's list using this information.


Just make the #1 repository the same across all desktops you will be installing on, and that will make them all consistent.
 
You can use also command line cpan, but should download nmake first and while configuring give it's path.

Corwin
 
Incidentally, Text::CSV_XS is a far superior and flexible module than Text::CSV.
 
I agree with Corwinsw - if nmake is available (or can be available) that is a better option. Get it straight from CPAN instead of a pre-built package from ActiveState.

perl -MCPAN -e"install Text::CSV"
 
I'm going to have to disagree, it takes a lot more than a make utility to make many modules, and dealing with compilation issues is a pain on any platform, and especially horrific on Windows when the module might have some *nix specific hook.

If ActiveState has a ppm binary, it's far easier to just use it instead. They don't have all the modules, or the latest versions, but it's rare that I've needed to use something that wasn't available. In that case, I can try to compile it myself, but have to make sure Visual C++ .NET is installed and the command line environment is set up before starting CPAN.

And I didn't know Text::CSV_XS was anything other than a C-optimized version of the pure-Perl Text::CSV module's API. It's up on PPM, too, and is a one command, five second install.

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
I will definitely take your word on that one. I'm primarily a Unix user, so if I don't download a Module's source straight from CPAN, then I use the -MCPAN method to install it, and that usually works great. I can't say that I have nmake installed on my PC, so I've never used the -MCPAN method in Windows - just Unix. I think the -MCPAN method in Unix is better than Active state PPM.

This post deals with Windows though, so I'll refrain from giving -MCPAN advice here ;)
 
Yeah, in the *nix world, you almost always have a compiler & environment set up so CPAN sources work great. It actually doesn't work too bad in Windows, if you've got all the tools available. Unfortunately, most people don't.

Downloading nmake will let CPAN install all the pure-perl modules, which does tend to be the bulk of them, but anything involving compiliation has the potential to get hairy. I never could get Gimp::Fu to compile, even after installing Gtk and tracking down libraries. Some things were never meant to be.

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
Text::CSV_XS allows greater flexibility by allowing you to specify the separator, quotes, escape characters, etc. This allows you to parse CSV-like data that doesn't correspond exactly to Text::CSV's concept of what a CSV file should look like. It also allows characters such as newlines to be contained in CSV fields, which Text::CSV does not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top