in reply to Perl is returning... odd results... from regular expressions. Things matching when they shouldn't, and stuff like that.

When embarking on something in Perl that seems simple but turns out to be complicated - which parsing CSV is - you should start looking around CPAN. Someone has very often already tackled your problem and provided a nice module to help others.

In your situation, take a look at Text::CSV::Simple or another CSV module. Trying to roll your own regex for this type of thing can be an exercise in frustration when you're really mostly interested in getting the job done.

  • Comment on Re: Perl is returning... odd results... from regular expressions. Things matching when they shouldn't, and stuff like that.

Replies are listed 'Best First'.
Re^2: Perl is returning... odd results... from regular expressions. Things matching when they shouldn't, and stuff like that.
by Groxx (Novice) on Jan 11, 2007 at 08:13 UTC
    I'll keep that module in mind, though I actually DO want to do it myself if possible. I'm also making this for someone else, so I want him to be able to modify it in my absense if needed (so it'll be commented like mad).

    Thanks for the link! Again, I'm new at this, so I probably wouldn't have found a good one on my first try.

      Actually, if you want someone else to be able to modify it in your absence, you'll even more want to use the module. The module's interface is way better than trying to read the code that actually does the work.

      Really.

      I mean it.

      In fact, if you want to really make your life easy, you may want to use DBD::CSV where you can just use a bit of SQL to insert into a new CSV table some sort of SELECT from the old CSV table. A lot of magic will happen under the covers, but it's magic that you don't need to write, maintain, comment, or play with. Same goes for your friend ;-) What you're left with is some really easy-to-tweak code that your friend should have much less problem playing with.