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:

  1. which class it falls into
  2. what are the values for each of the parameters

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!


In reply to Parsing/Deparsing a Formatted String by AdriftOnMemoryBliss

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.