in reply to Regex and split()
One obvious problem is that is will throw away white space unless it is contained in "". But you could probably fix that if you wanted.$str = 'a, "b,c", d'; @array = eval('('.$str.')');
#!/usr/bin/perl #set string to split on "," my $str = 'a,"b,c",d'; #use perl to parse an array as it normally would # # after the eval this next line will look like: # my @a = (a,"b,c",d); # # so $a[0] = 'a', $a[1] = 'b,c', and $a[2] = 'd' my @array = eval("(".$str.")"); #catch errors from eval if( $@ ) { die "eval error: $@\n"; } #print out the results. foreach (@array) { print $_, "\n"; }
|
|---|