Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Complex Data Structures

by samtregar (Abbot)
on Jun 18, 2002 at 18:00 UTC ( [id://175443]=note: print w/replies, xml ) Need Help??


in reply to Complex Data Structures

I think the most complex data-structure I've ever created was for HTML::Template. The module has two main structures - an array of ops including variables, text, loops and conditionals (@stack) and a hash of parameter names to the corresponding variable or loop (%map). The trick is that both the map and the stack point to the same underlying storage. This allows me to do something like this to set the value for a variable:

${$map{var_name}} = "text for var_name";

Then when I get to the place where I want to use the variable on the stack I just do:

$output .= ${$stack[$i]};

Since the same scalar is referenced from both @stack and %map I can get access to them both quickly and with no copying required.

Now, setting up this structure is indeed a royal pain in the ass but the payoff in output speed makes it all worthwhile. (Of course, these days all the real speed demons have moved on to HTML::Template::JIT!)

-sam

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://175443]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-26 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found