in reply to Re^2: Splitting a line on just commas
in thread Splitting a line on just commas

Response: I was about to say, you might want to remove all the undefined created by the unmatched parens, before removing the blank fields.
@values = grep{defined} @values; @values = grep{$_ ne ''} @values;
or
@values = grep{defined && $_ ne ''} @values;
Again, I would not use this method. It's not good to remove blank string values. As for the equal footing, would this be any less equal: /(?:\,)|(\".*?\")/

Update: I did forget to include the trailing comma after the quotes, but I still wouldn't use it: /\,|(?:(\".*?\")\,)/


Demize

Replies are listed 'Best First'.
Re^4: Splitting a line on just commas
by ikegami (Patriarch) on Jun 14, 2010 at 18:05 UTC
    The point is that there's no point if removing the extra stuff if you extract the fields right in the first place. It's already been shown how to do that.
      The proper extraction method has not been shown, Anonymous came closest, but as stated, it's still a problem. He used a 2-step method, which I think the most of us were trying to solve in one step, though using [^"]* rather than .*, is necessary.


      Demize

        Whoa, how did you come to think that using two steps makes it wrong. Besides, you can easily make it take one step by changing it to

        my @fields = $s =~ /("[^"]*"|[^,]*)(?:,|$)/g;

        Of course, there's still the question of values with quotes or newlines, space around the comma, etc. But yours didn't even attempt at handling any of those either.

        The proper extraction method has not been shown

        Seeing the mess that's resulting from people trying to reinvent the wheel, I'd argue I showed the proper extraction method.

        [ Duplicate post. Please ignore.]

        Whoa, how did you come to think that using two steps makes it wrong. Besides, you can easily make it take one step by changing it to

        my @fields = $s =~ /("[^"]*"|[^,]*)(?:,|$)/g;

        Of course, there's still the question of values with quotes or newlines, space around the comma, etc. But yours didn't even attempt at handling any of those either.

        The proper extraction method has not been shown

        Seeing the mess that's resulting from people trying to reinvent the wheel, I'd argue I showed the proper extraction method.