473,395 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

CSV file manipulation

8
OK... the important bit here is that I am not able to compile in an external module right now.. long story but I can't !

I have a csv file, comma delimited. Problem is that some fields which are provided as quote delimited also have commas in.

I want to parse the data line to remove commas that fall between quotes, before then splitting the line as per normal.

Could anyone give me or point me in the direction of some native perl code that will do this ?

Many thanks

Keith
May 14 '07 #1
5 2216
miller
1,089 Expert 1GB
Hello Keith,

Even if you're not able to install an external module, I would still advise you to use an external package, and just install it in your local user.

cpan Text::CSV 0.01

Download the source from the above package, and put it in the subdirectory "Text" from whenever you are creating your script. Then simply use the package exactly like the examples provided.

It is generally not a good habit to get into to do this, but if you have no other choice, it still saves you from reinventing the wheel. And at the very least, you can simply look at the source and learn how you might accomplish this functionality on your own.

- Miller
May 14 '07 #2
keithl
8
Hi Miller,

Thanks for that - I did not realise that the modules could be used in such a way.
Does that appy for any of the generally available perl modules - specifically DBI ?

Many thanks

Keith
May 14 '07 #3
miller
1,089 Expert 1GB
Some modules are not pure perl, and require compiling in some way. Some modules are dependent on other modules, and so you need to "install" all dependencies.

In general it is a bad idea to start downloading and using modules in the way that I described, but if you have no choice, then it's an option. I would not advice you to do it for DBI, or any larger more complex modules. But something like Test::CSV is extremely simple and isn't going to be changing ever.

In my own case, I never do this, but I have root permissions on all machines that I use so I use cpan to install packages. However, I have looked at the source of certain modules to determine how they work when they did not directly solve the problems that I wanted. It's a great way to learn.

- Miller
May 14 '07 #4
keithl
8
Hi Miller,

One more question ! lol

When I install and run my script as you suggested I get the following message:

$ ./process_inerl01.pl
Can't locate auto/Text/CSV/autosplit.ix in @INC (@INC contains: /usr/opt/perl5/
ib/5.8.0/aix-thread-multi /usr/opt/perl5/lib/5.8.0 /usr/opt/perl5/lib/site_perl
5.8.0/aix-thread-multi /usr/opt/perl5/lib/site_perl/5.8.0 /usr/opt/perl5/lib/si
e_perl .) at /usr/opt/perl5/lib/5.8.0/AutoLoader.pm line 158.
at Text/CSV.pm line 23

But the script still appears to run. Is this something I should be worried about at all ?

Many thanks for your help again

Keith
May 15 '07 #5
miller
1,089 Expert 1GB
Well, these are the types of issues that you run into when you do not install a module in the standard way. I personally would probably edit the module to remove the messages, but I have more experience doing that type of thing than you probably.

I'll go ahead and tell you how to do that, but if there are any further messages, I would advise you to just try to convince the sysadmin to install Text::CSV, or just ignore the messages.

Move these lines (32-34) to the end of the file

Expand|Select|Wrap|Line Numbers
  1. 1;
  2.  
  3. __END__
  4.  
Edit line 26 to equal. I removed the AutoLoader

Expand|Select|Wrap|Line Numbers
  1.   @ISA =         qw(Exporter);
  2.  
And remove line 23 entirely.

Expand|Select|Wrap|Line Numbers
  1.   use AutoLoader qw(AUTOLOAD);
  2.  
Now, this should remove the warning message and still have everything work perfectly. However, I haven't tested this, so I suggest that you make a backup of the file before you start editting it.

Anyway, good luck with your project,
- Miller
May 15 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Paul Moore | last post by:
Does anyone know of a Python library which handles sound file formats (MP3, Ogg, FLAC are the three I'm nost interested in). I'd like something that can manipulate "metadata" - stuff like artist,...
7
by: Dennis C. Drumm | last post by:
I would like to be able to update an xml file located on my hosted server from my local computer. The server requires a user name and password to access the web site for writing or updating...
1
by: ma740988 | last post by:
Trying to some of my reading on file manipulation (ifstream/ofstream/fstream) into action. So now consider. # include <iostream> # include <fstream> # include <cstring> # include <sstream> ...
2
by: PFI | last post by:
Hi, I recently installed SQL Server 2005 Enterprise Edition (9.0.1399) and I have problems on queries concerning system file manipulation... For example, when I try to increase the Log File of...
4
by: magix | last post by:
Dear Guru, I'm not so good in file manipulation, but would like to seek for help here. I have following basic code of command line argument as starting point (the code below output the...
1
by: scubber | last post by:
hi, im new (as you're going to painfully aware of in a minute) to programming and was wondering if anyone could help with this little problem: i am trying to read a number of values which are...
0
by: L'eau Prosper Research | last post by:
Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases new TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set. L'eau Prosper Market...
0
by: L'eau Prosper Research | last post by:
NEW TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set By L'eau Prosper Research Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases...
1
by: tourist.tam | last post by:
Hi, I am trying to read a file using a BufferedStream and avoiding at maximum the use of string manipulation. I need now some help understanding on how to use byte array to hold the data and...
15
by: pakerly | last post by:
How would i do this, convert a test file to excel? Lets say my text file has fields like this: NUMBER NAME ADDRESS PHONE 11002 Test1 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.