Just use Text::CSV_XS and be done with it. Parsing strings with arbitrary delimiters which may or may not be present in the actual data isn't exactly a hard problem, but there are too many special cases to concern yourself with that end up making a simple split on a regex painful. Seeing as this is a common problem, someone has taken the time to put it in a module so that we don't need to continue to worry about those special cases and, instead, concentrate on the real problem at hand.

In fact, I would suggest using DBD::CSV instead, as it takes care of yet another layer or three of abstraction so that the data in your table really gets treated like data, again, to allow you to concentrate more on business logic than data logic.

Of course, from there, it's a relatively small step to put the data in a real database (whether SQLite, MySQL, DB2, Oracle, or whatever) and gain further abstraction, speed, and utility. This is my goal for nearly all my data. I can't always get there, but I do try to design my data that it COULD get to a database, which includes using DBD::* whenever possible.


In reply to Re: good delimiter in data for Perl by Tanktalus
in thread good delimiter in data for Perl by sathiya.sw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.