Consider using an existing data serialization language.

I enjoy using YAML for configuration information or other external data. It's advantages are that it is easy to read and write with any text editor, the syntax is fairly intuitive (it looks a lot like outlines done in email), and there are decent parsers and emitters for many common languages, including Perl (YAML).

One of the very nice things about YAML is that it is a direct representation of scalar, array and hash data structures, nested arbitrarily. This means that the language is rich enough to represent any data structure that you can in Perl (or Python, Ruby, JavaScript, PHP, etc.). It also means that you don't have to perform interesting data contortions (or use objects, tree structures, etc.), as you might with XML. Rather, you use the structure directly. It's an AoHoAoH, or what ever you like.

Your data in YAML might look like:
#!/usr/local/bin/perl use YAML; use Data::Dumper; my $data = join '', <DATA>; my $pages = Load( $data ); # YAML does the syntax checking and parsing. # It is still up to you to perform data validation. print Dumper( $pages ); __DATA__ # this is your data, represented in YAML - page: p1 questions: - name: 4B label: Do you like your pie with ice cream? single: - Yes - No - name: 4C label: Do you like your pie with whipped cream? single: - Yes - No # and so on ... # - page: p2 # questions: # -
The Perl data structure looks like this:
$pages = [ { 'page' => 'p1', 'questions' => [ { 'name' => '4B', 'label' => 'Do you like your pie with i +ce cream?', 'single' => [ 'Yes', 'No' ], }, { 'name' => '4C', 'label' => 'Do you like your pie with w +hipped cream?', 'single' => [ 'Yes', 'No' ], } ] } ];

-Colin.

WHITEPAGES.COM | INC


In reply to Re: Parsing a macro language by cmeyer
in thread Parsing a macro language by bluetrust

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.