P
Prototype
I've got a string something like this:
$text='val1 , val2 , max(val3,val4)'
which I want to parse into its individual components:
@parts=split(/,/,$text)
but this simplisitic approach doesn't cope with the last part of $text
which contains a bracketed expression containing the delimiting ","
character.
I've read perldoc -q delimited, and this gives useful guidance for the
similar case of:
$text='val1 , val2 , max "val3,val4"'
but brackets are more difficult to cope with, and the methods shown
here can't be directly applied (think of nested brackets for example)
I'm aware of Text::Balanced, which I think may be part of the
solution, but I can't see how!
The only solution I can see at the moment is the fairly brute-force
approach of going through the string a character at a time, counting
open & closing brackets and only splitting into a new array element
every time a comma is found AND the bracket count is zero.
Something tells me there is probably a more elegant approach than
this! Anyone care to suggest it to me please ;-)
Paul.
$text='val1 , val2 , max(val3,val4)'
which I want to parse into its individual components:
@parts=split(/,/,$text)
but this simplisitic approach doesn't cope with the last part of $text
which contains a bracketed expression containing the delimiting ","
character.
I've read perldoc -q delimited, and this gives useful guidance for the
similar case of:
$text='val1 , val2 , max "val3,val4"'
but brackets are more difficult to cope with, and the methods shown
here can't be directly applied (think of nested brackets for example)
I'm aware of Text::Balanced, which I think may be part of the
solution, but I can't see how!
The only solution I can see at the moment is the fairly brute-force
approach of going through the string a character at a time, counting
open & closing brackets and only splitting into a new array element
every time a comma is found AND the bracket count is zero.
Something tells me there is probably a more elegant approach than
this! Anyone care to suggest it to me please ;-)
Paul.