in reply to regex - parsing a string with many optional fields
If I run the code you provided, with the string you provided ("P1D"), the match suceeds, and I get this in @temp:
To me that looks like what you should be getting, given the approach you've chosen - each field in the grammar will always come into the same array field.DB<1> x @temp 0 undef 1 'P' 2 undef 3 undef 4 undef 5 1 6 undef 7 undef 8 undef
Could it be that you saw that first undef and didn't realize that the data was in the later fields?
With the approch you're using, when the regexp doesn't match, you will get an empty array, so test for that. (Maybe by looking at $#temp).
|
|---|