in reply to Extracting data from CSV file + Extracting selected few lines through perl

Not directly related to your OPed question, but if you're doing a lot of CSV file parsing, please consider one of the many, fine CSV support modules avaliable through CPAN (Text::CSV is the prime candidate) and maybe you can reduce your Tylenol | Acetaminophen intake somewhat.

Replies are listed 'Best First'.
Re^2: Extracting data from CSV file
by Laurent_R (Canon) on Dec 18, 2014 at 22:36 UTC
    Well, I am sorry, I understand your point, but I have to disagree somewhat with that. Yes, in the general case of CSV files with complicated rules on separating, escaping and quoting characters (and so on), by all means use the Text::CSV or some other CSV specialized module.

    But you don't need a 30-ton truck to deliver one TV set to a residential home. (It might even be counterproductive.)

    To me, using a CSV module for such an extremely simple CSV file is just plain over-engineering or technical overkill. For that, the split is just the right tool, efficient, simple, very well integrated into the language, easy to use. I do not see any reason to make things more complicated than they should be when they can be very simple. This is really not my view of the Perl philosophy: make simple things simple...

    Update: Hehe, 3 negative XP points for stating something that should be obvious, i.e. that there is not just one single solution for absolutely everuthing, I thought the monks here had more freedom to think independently. ;-)

      Even on simple CSV data, Text::CSV_XS (not Text::CSV) can outperform plain perl (using split) given the right options and using the right methods. YMMV. Note, for the given data it most likely will not be faster

      The main reason to start using Text::CSV_XS (or Text::CSV) even with simple CSV data is that moving onward when the data changes (yes, it will, eventually) or on other projects that look simple but are not.

      For programmers that know both approaches, you are definitely right. No single modules (or tool or even language) is the best choice for every problem, but when in doubt, choose the option that is most versatile and best documented and that will also help you with likewise problems in the (near) future.

      Even the simplest change, like changing the line ending from \n to \r\n will make you happy having made that choice as early as possible.


      Enjoy, Have FUN! H.Merijn

      I kinda agree with your disagreement, but then, on the other hand, not so much. I tried to qualify my post ("Not directly related to your OPed question, but if you're doing a lot of CSV file parsing...") to make it clear that what I had in mind was more like using a 30-ton truck to deliver a 30-ton load.

      And then there are also Tux's well-founded points (++).

        Quite possibly I slightly misinterpreted your post and overreacted to it, sorry for that, but also I duly qualified my own post, saying that I understood what you were saying, that I "somewhat" diasgreed and noting that the CSV modules are really the solution when it gets more complicated. We've taken slightly different points of emphasis, but I am pretty much convinced that we think almost identically on the deeper subject.

      Update: Hehe, 3 negative XP points for stating something that should be obvious, i.e. that there is not just one single solution for absolutely everuthing, I thought the monks here had more freedom to think independently. ;-)

      If it is so obvious why did it need stating?

      Basically you pounced on chided criticize complain at AnomalousMonk for saying: now that you've gotten a solution, FYI this other thing exists also

      The split solution did not need defending, it was code solution , ready to use, not a link to a manual for another thing that could be used ... an actual solution for immediate data

      OP:
      I'm going fishing today, I need boots quick, help
      toolic:
      Here is some nylon and duck tape, it should last you one trip easy
      AnomalousMonk :
      you know, indirectly, for about the same price (free) there are boots on CPAN
      Laurent_R :
      i'm sorry I disagree, free boots are 30-ton truck of over-engineering , nylon+ducktape is perl philosophy of make things simple

      Still funny :)

      Well, I am sorry, I understand your point, but I have to disagree somewhat with that.

      Hehe ... hey buddy, if you're doing a lot of this kind of thing, there are modules for that, you know, FYI ... its overkill to consider alternatives