CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
File Splitting


New User

Jan 30, 2003, 8:10 AM

Post #1 of 4 (2657 views)
File Splitting Can't Post

I am having a csv file with 5 columns.One of the column is
a description of length 50characters and may have any characters like comma or hypen as part of the description. I am using comma as the delimiter to split the file to do the validations as the columns may not be of fixed length. But if the description has a comma ,
it is being split in to two
sample data looks like this...

C5,L10,ACTB,"OldACTB-MultisDecile1,2""", gokavars
C5,L05,ACTM,New LTV/ACTB - Manhattan , gokavars
N4,L52,ACTB,ACTB - 3X+ MULTIS DECILE 4 ,gokavars

After running my program
my data looks like this

C5 | L10 |ACTB |"OldACTB-MultisDecile1| 2"""
C5 | L05 | ACTM | New LTV/ACTB - Manhattan | gokavars
N4 |L52 |ACTB | ACTB - 3X+ MULTIS DECILE 4 |gokavars

Is there anyway I can make the first row look like
C5 | L10 |ACTB |"OldACTB-MultisDecile1 2""" | gokavars


Jan 30, 2003, 9:47 AM

Post #2 of 4 (2653 views)
Re: [gokavar] File Splitting [In reply to] Can't Post

Your best bet would be to pick a delimiter that is unlikely to show up in any of your data, such as a pipe | or a carat ^. Perhaps even use a double character for a delimiter || or ^^.

"...there's some good in this world, Mr. Frodo, and it's worth fighting for." - Samwise Gamgee, The Two Towers

New User

Jan 30, 2003, 11:41 AM

Post #3 of 4 (2647 views)
Re: [Melvosh] File Splitting [In reply to] Can't Post

This is a specific requirement for me where I have to use a comma delimited file. I figured out something called
quotewords function,but it is returning some error..

here is the piece of the code..

open(f1, "<$infile") || die "Can't open $infile $!" ; #--f1 is input data file

local @newarr=<f1>;

here am getting an error as

" Unmatched quote"..

Any idea


Feb 3, 2003, 1:54 AM

Post #4 of 4 (2633 views)
Re: [gokavar] File Splitting [In reply to] Can't Post

The Text::ParseWords module (that comes with the standard Perl distribution) can be used to process CSV files with embedded commas.

If your requirements get any more complex then you should look at the Text::CSV module from CPAN.

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives