Hi,
Below is an example of a record I have, which I wish to split using the perl's split function and load it into an array. I am having tough time figuring out the exact reg-ex to perform the split.
Given record:
"a","xyz",0,2,48,"abcd","lmno,pqrR, stv",300,"abc",20,
The delimiter to uniquely identify each field is "," (comma). The quotation marks represents a string and the non-quotation marks represents integers.
The problem with this record is such that, a string which is represented within the quotation marks has "," (commas) (example this "lmno,pqrR, stv") in it, which should not be identified as a field, because the comma resides within the quotation marks.
Therefore, I would like to build a reg-ex within the split function which will basically follow the either of the below algorithms:
Algo A:
split (/\,|dont split if there is [:alpha:]\,[:alpha:]|dont split if there is [:alpha:]\,|dont split if there is ,[:alpha:]/, $givenrec)
--------------OR---------------
Algo B:
split a field if the starting and ending character of that field is " (for strings) OR none (for integers)
I really appreciate the help in advance.
Please let me know if you require any further explanations.
Thus the result should be: That is retaining the quotation marks as well, since its string.
"a"
"xyz"
0
2
48
"abcd"
"lmno,pqrR, stv"
300
"abc"
20