Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Multiline CSV and XML

by dHarry (Abbot)
on Sep 29, 2010 at 12:41 UTC ( [id://862605]=note: print w/replies, xml ) Need Help??


in reply to Multiline CSV and XML

I have difficulty understanding what exactly you do in your code. You seem to over-complicate things. There are several modules available for parsing CSV files, no need to reinvent the weel. It would probably reduce your code by 30% or so. I would not worry too much about footprint, you control the opening/closing of files and wether you slurp them or not.

Also for generating the XML files you can use a module. You could for example start by taking a look at XML::Simple which seems enough for what you need to do.

Replies are listed 'Best First'.
Re^2: Multiline CSV and XML
by sanju7 (Acolyte) on Sep 29, 2010 at 14:50 UTC

    Hi dHarry,

    Its not about reinventing the wheel, the system hosting the code is a hybrid one and has an embedded perl (dds perl) running on them. That simplest of task like installing perl modules is not as straight forward and not necessarily all modules supported. It breaks the code and in my previous attempts had been failure with text::csv modules .

      I can see where you might have trouble building Text::CSV_XS but you should be able to use Text::CSV_PP.

      I mean no disrespect and I realize that English is (probably) not your first language but I'm having a hard time trying to figure out what the problem is here. You said ...

      I am not getting how to device the parseCSVLine and readCSV modules

      I don't know what you mean when you say you want to "device" those "modules" (which are actually subroutines). If you can use Text::CSV_PP will you still have the same problem? If not, can you ask the question again in a different way?

      I don't think your language is Spanish but, For What It's Worth, puedes preguntarme en privado en Espanol. (My apologies to any actual Spanish speakers with real keyboards.)

        Let me ask the question a bit clearly. Consideration 1(no use of external module):

        How can i have readCSV subroutine read and populate multiple array lists if there is more than one rows? I am fairly new to perl and yet to get over common mistakes.

        The readCSV sub does read the csv files on the fly and creates each XML at its directory. This goes fine with XMLs where there is only one row. In readCSV i could read the rows to array list and extract the elements of the array against its column heading (as key) and extract that value to variable to be used to create the XML with generateXML sub.So i don't need to care about computing rows and populating no more than one array list

        Now when there is multiple rows at the CSV the situation changes . Now readCSV not only have to sort keys so as to get the values from the first array list it reads it would need to count rows there, if more than one then read one row at a time each one to separate array list, it should do that dynamically so parseCSV can parse each array list do the regex substitution etc (whatever operation may require). This would do the cleanup/ manipulations apply rules and pass it to generateXML all in one go.

        Consideration 2(use of external module):

        As a personal preference i should probably use a module the do the job, making the life a lot easier but saying that is easy, than doing because i have inherited bunch of other scripts and i really don't want to see them break if i change the code entirely. I would start creating the whole thing ground up fresh but for now i thought to fix this would be of less time than to start afresh with readCSV_PP start afresh with readCSV_PP or any other module in this regard.

      I am still to figure the puzzle. Is there a better way to construct the code even with using modules. I will try to install them if its possible.

      Can anyone tell me how can i access multiple lines as hash of hashes against 1st row fields(column heading) as key from a multiline csv

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://862605]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2024-04-25 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found