in reply to Help with Regex in Split
In general, you should be using one of the CSV parsing modules, like Text::xSV or DBD::AnyData, but if your data is really formatted and as simple as you describe it, the approach of matching what you want to keep instead of splitting away what you want to discard produces good results:
#!/usr/bin/perl foreach $entry (<DATA>) { ($var1, $var2, $var3) = ($entry =~ /"([^"]+)"(?:,|$)/g); print "Var1: $var1\n"; print "Var2: $var2\n"; print "Var3: $var3\n"; } __DATA__ "value 1","something else","other stuff" "asdf123","omg","hope this works" "more tests","testy","blah"
I find that whenever something is hard to split, I'm approaching the problem from the wrong end and should be matching what I want to keep, and vice versa.
|
|---|