in reply to Parsing a string

Like this?

$s = q[ci,14938340,2,"Monday, February 21, 2011 19:58:06 UTC",34.6953, +-118.5350,2.2,17.40, 9,"Southern California"];; print for $s =~ m[("[^"]+"|[^,]+)(?:,|$)]g;; ci 14938340 2 "Monday, February 21, 2011 19:58:06 UTC" 34.6953 -118.5350 2.2 17.40 9 "Southern California"

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Parsing a string
by kepler (Scribe) on Feb 22, 2011 at 17:26 UTC
    Really nice :) Thanks - it's a wonderul solution and its module independent; I don't have the mentioned module in my webserver (do you believe that???) Kind regards, Kepler

      Be aware that the given regular expression has a chance to be broken in some circumstances.

      Example:

      $s = q[ci,14938340,2,"Monday, February 21, 2011 19:58:06 UTC",34.6953, +-118.5350,2.2,17.40, 9,"Southern California, \"US\""]; print for $s =~ m[("[^"]+"|[^,]+)(?:,|$)]g;

      Output

      ci 14938340 2 "Monday, February 21, 2011 19:58:06 UTC" 34.6953 -118.5350 2.2 17.40 9 "Southern California \"US\""
      --
      Regards
      - Samar
Re^2: Parsing a string
by Monkomatic (Sexton) on Feb 22, 2011 at 18:27 UTC

    Yeah this was a really clean solution. Very nicely done.

    I was going to suggest something more complicated like the below for subtracting uniques. But you would have had to do it for each data type.

    # CODE for finding a number field of a certain length if (my @matches = $datainstring =~ m{ ([0-9]{12}) }xmsg) { print qq{matched @matches};push(@match2, @matches);foreach my $elem + ( @match2 ) {next if $seen{ $elem }++;push @unique, $elem;}### GET U +NIQUES ##### } # IF #