Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 17:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found