in reply to Re^3: problems parsing CSV
in thread problems parsing CSV
Once again, I strongly recommend you move the object constructor outside the while loop. Tux, a.k.a. H. Merijn Brand, the author of Text::CSV_XS, which is the base module you're indirectly using, amplified this suggestion in his reply to your post. He explained that "you create a new csv parsing object for every line read." You really don't want to do this needlessly for 1.7 million records. And Tux's advice to use getline instead of <>/parse/fields is a wise one.
I think you're trying too hard to handle the floating-point weight values. Just be explicit with your tests:
if ($pounds == 0.0 and $grams == 0.0) { ... }
The right coercions happen automagically. Here's the proof:
D:\>perl -E "say '' == 0.0 ? 'Equals' : 'Does not equal'" Equals D:\>perl -E "say '0' == 0.0 ? 'Equals' : 'Does not equal'" Equals D:\>perl -E "say '0.0' == 0.0 ? 'Equals' : 'Does not equal'" Equals D:\>perl -E "say '123' == 0.0 ? 'Equals' : 'Does not equal'" Does not equal D:\>perl -E "say '123.4' == 0.0 ? 'Equals' : 'Does not equal'" Does not equal D:\>
So you didn't like any of the other improvements I suggested in my refactored version of your script?
Jim
|
|---|