AdriftOnMemoryBliss has asked for the wisdom of the Perl Monks concerning the following question:
Howdy Monks,
I have a database of strings that can fit into a series of defined format classes. For example here are some examples, along with a description of the formats:
t(1;3)(q15;p13) ==> t([int], [int])([p|q][int], p|q][int]) inv(1)(p13p11.1) ==> inv([int])([p|q][int][p|q][int]) +3 ==> +[int]
I need to be able to "round-trip" from these formats. That is, I need to be able to take a formatted string and determine:
I also need to be able to take those same to data-types and create the formatted string -- that's what I mean by "round-tripping".
I have the regex's and logic set-up for doing the first part, but is there a way to combine that with the round-tripping? For example, can I use a reg-ex like the one below to create a new string by giving it values of $1, $2, $3, $4?
qr/^der\((.{1,2});(.{1,2})\)\(([p|q].*);([p|q].*)\)$/
Alternately (and perhaps better), is there another way to get this done that stores the formats and "logic" in a single place? Any ideas/comments very much appreciated!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing/Deparsing a Formatted String
by ikegami (Patriarch) on Jun 15, 2005 at 19:57 UTC | |
|
Re: Parsing/Deparsing a Formatted String
by GrandFather (Saint) on Jun 15, 2005 at 22:57 UTC | |
|
Re: Parsing/Deparsing a Formatted String
by kral (Monk) on Jun 16, 2005 at 09:46 UTC |