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

Re: Suggestions for simplifying script to parse csv data

by graff (Chancellor)
on Jul 28, 2007 at 14:53 UTC ( #629294=note: print w/replies, xml ) Need Help??


in reply to Suggestions for simplifying script to parse csv data

It looks like you might have some mistakes in your explanation (e.g. your first "parsing rule" refers to "FWIA770", but your sample output data contains "FWA1770"), and there are some unexplained details in the data. (E.g. where do output strings like "FTSE" and "AWBRIC" come from? I didn't see these in the input or code as originally posted.)

And you don't mention whether the ordering of array elements in the output AoH is important -- if the results need to be in a particular order, this affects how complicated or simple the script can get.

I gather that parsing the CSV input isn't the main thing you're asking about. You want to know how to simplify and shorten the code you posted. The basic rule to apply there is: figure out how to eliminate repeated lines of code. As originally posted, your code contained the same set of assignment statements repeated in two or three different places, and this is most likely unnecessary. The code would be simpler, clearer, and easier to maintain/update if you reorganize or refactor it so that the repetitions aren't needed there are no repetitions.

And apart from that, don't use a reference to a hash when just a simple hash will do (i.e. replace  $row = {}; with  %row = (); and then when pushing row hashes onto your output array, do it like this:  push @IndxData, { %row };

Finally, you might decide that some of your temporary-storage variables aren't needed at all (e.g. do  for ( split /\|/, $Currency ) instead of assigning the split to an array just to loop over the array).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2022-12-04 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?