regexp help needed
am 15.09.2005 22:26:38 von Chuck CarsonI need to parse a long string of values that are always seperated by
commas with no white space anywhere in the stream. Any given line may
contain null values (thus you see to comma's in a row)
Here is a sample input line:
140,0,3,0,adcbkp20_os,full,adcbkp20,adcbkp20,1126489655,0000 000207,1126489862,ADCBKP20,1,,5640064,117305,,100,14035,root ,1,0,0,90,,adcbkp20,2,2,0,,,0,0,0,43570,,,,,,14044,,,,,0,,,1 ,0,0,adcbkp20_1126489655,,
I have a regexp that accounts for every possible character type in each
field, but my match never succeeds so I am thinking that the null
fields are causing the problem.
Here is my regexp:
m/(\d+),(\d+),(\d+),(\d+),([a-zA-Z0-9_\-.]+),(\w+),([a-zA-Z0 -9_\-.]+),([a-zA-Z0-9_\-.]+),(\d+),(\d+),(\d+),([a-zA-Z0-
9_\-.]+),(\d+),(\d+),(\d+),(\d+),([a-zA-Z0-9_\-\/.]+),(\d+), (\d+),(\w+),(\d+),(\d+),(\d+),(\d+),(\w+),([a-zA-Z0-9_\-]+), (\d+),(\d+),(\d+),(\d+)
,(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),([a-zA-Z0-9\(\)]+),([a- zA-Z0-9_\-.]+),([a-zA-Z0-9_\-.]+),(\d+),(\d+),([a-zA-Z0-9_\- .]+),([a-zA-Z0-9_\-.]+)
,([a-zA-Z0-9_\-.]+),([a-zA-Z0-9_\-.]+),(\d+),(\d+),(\d+),(\d +),(\d+),(\d+),([a-zA-Z0-9_\-.]+),(\d+),([a-zA-Z0-9_\-.]+)/
My question I guess is how do I get this to match?
$var = "100,,adcbkp20-b";
if ($var =~ m/(\d+),(\d+),([a-zA-Z0-9_\-]+)/ ) { print "match.\n"; }
Thus, the second field is null, woulnd't $2 be undefined yet the entire
string will match? (thus $1 and $3 have values) If not, how can I
achieve this?
Thanks,
CC