>>>>> "SR" == Simon R <[EMAIL PROTECTED]> writes:

  SR> OK... I've been toying with this for a day now and it's time to set the
  SR> experts loose. I need to be able to split a string of the form

  SR> foo,bar',name=simon,age=99

  SR>  into its constituent parts (comma is the delimeter). So far so good and
  SR> very simple using split().  However, I also need to be able to handle the
  SR> case where there may be commas in a phrase enclosed by quote marks, in 
which
  SR> case we should NOT split on those commas;

  SR> e.g.

  SR> foo,bar,names="charlie,john,ann",ages='20,30,40' must be split to

  SR> foo
  SR> bar
  SR> names="charlie,john,ann"
  SR> ages='20,30,40'

this seems to do the trick. it does assume no quotes inside a quoted
value. that can be handled with escape detection via lookbehind before
the matching quote.

uri

while( <DATA> ) {


        print "$1\n" while /(\w+(=(\w+|(['"])[^'"]+\4))?),?/g ;
}

__DATA__
foo,bar',name=simon,age=99
foo,bar,names="charlie,john,ann",ages='20,30,40'


output is:
foo
bar
name=simon
age=99
foo
bar
names="charlie,john,ann"
ages='20,30,40'






-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to