A decent starting point might be looking at Config::General. Its a module which parses Apache conf style config files, and I think could get you off on the right start.
Example file and how Config::General parses it.
# File blah.conf
<graph>
<node>
title = node1
<loc>
x = 10
y = 20
</loc>
</node>
<node>
title = node2
<loc>
x = 10
y - 29
</loc>
</node>
<edge>
sourcename = node1
targetname = node2
</edge>
</graph>
# After parsing file and placing into %conf you will have
%conf = (
node = {
title = {
node1 = {
loc = {
x => 10,
y => 20,
},
},
node2 = {
loc = {
x => 10,
y => 20,
},
},
},
},
edge = {
sourcename => node1,
targetname => node2,
},
)
# You can then reference pieces thereof via
$conf->{node}->{title}->{node1}->{loc}->{x};
I might have messed up the indentation, as to how it builds the hashes, but I think the point is clear. Also if you do something like x = 10 20 30 40, when you reference conf->{x} it will return an array ref, the contents of which is 10, 20, 30, 40.. you can alter the delimiter, which is whitespace by default to something else, so on and so forth with all the perl yummy goodness.
So my suggestion would be to grab the module, look over its parser and building routines, and then abstract it out as you see fit. It should be a reasonable exercise to port the hash of hash structure, to say a C struct.
Best of luck and happy hacking
/* And the Creator, against his better judgement, wrote man.c */
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.