Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Suggestions to make this code more Perlish

by Laurent_R (Canon)
on Mar 30, 2014 at 10:06 UTC ( [id://1080276]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Suggestions to make this code more Perlish
in thread Suggestions to make this code more Perlish

Thanks for your comments, Ken. Yes, you are right, this is a 10-minutes solution, certainly not a polished one.

I needed to process the first line differently because of the way I chose to process the other lines, which would not work for the first one, but it is certainly possible to find another way to process the lines that would also work for the first one. However, when I have a header line that needs to be processed differently than the rest of the file, I often prefer to process it before starting to loop on the rest of the file, because the algorithm is then simpler (and often faster, which matters if the file is large).

You are right on the "join" line, it adds a field separator at the end of the records. That did not shock me, but it is indeed different from the output produced by the code in the original post. Adding parens (as per your proposal) solves the issue.

I had not even seen that there were two "irregular" lines with quoted fields at the beginning of the records in the input data, and that of course is a serious problem because it probably means that the whole algorithm has to be modified. BTW, this is a good example of why using a module such as Text::CSV is often better than doing one's own solution.

  • Comment on Re^3: Suggestions to make this code more Perlish

Replies are listed 'Best First'.
Re^4: Suggestions to make this code more Perlish
by kcott (Archbishop) on Mar 30, 2014 at 13:24 UTC
    "BTW, this is a good example of why using a module such as Text::CSV is often better than doing one's own solution."

    Yes, I absolutely agree. Beyond being an interesting academic exercise, reinventing this particular wheel has little merit.

    Furthermore, while solutions have been coded for a very specific input, they'll need to be recoded for escaped quotes, whitespace around field separators and anything else that Text::CSV has already taken into consideration but which we haven't catered for yet.

    -- Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found