Hi. I am experimenting with tied hashes, XPath, the DB module, and XML tree data structures in Perl

I have a statement where $x is a reference to an object and a tied hash as below:
$x->{one}{two}{three};
I want to "autovivify" keys 'one', 'two', and 'three'. These keys represent XML tags. However, using the tie hash function calls like FETCH and STORE, I really want to create a data structure of hashes with an anonymous array sandwiched between each key. An anonymous hash in the anonymous array will hold the information about the "key". This gets crazy when I want to have tags of the same name as children of the same node, but I want to access them with my "Perl" syntax. (I will also want to maintain the them in the order created.)
$x->{one}{two}{three}; $x->{one}{two}{four};
Hopefully, you have followed me so far. Now I will get to the point.

My question really is: Why do I have to bend over backwards to create "code" in the Perl syntax? Why can't I suddenly break into a user-defined syntax that maps to my code and objects? For instance:
use MyClass::XML::XPath; use syntax 'http://www.blah.com/xpath/blah.blah', 'MyClass::XML::XPath +'; /html/head/title[0] = "Page Title"; /html/body/h1[0] = "Some text here"; /html/body/form/input[@type="text" and @name="input"]; /html/body/form/input[@type="submit" and @name="Submit"]; print /*; my $title = /html/head/title[0];
By using the concept of autovivification in tandem with the XPath syntax, I should be able to automatically create an XML tree and populate/access it by using my own user-defined syntax. (Also, it would be cool to have an implicit XML tree -- sort of like the variable $_).

With Perl everything seems possible. How might I go about creating a user-defined syntax that maps to a class module? It seems like the DB module might be the starting point to override Perl functionality.

I am certain this is possible with a clever hack. Any assistance is greatly appreciated. Thanks.


In reply to User-Defined Syntax, XPath, Tied Hashes, and Autovivification by hackdaddy

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.