Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Complex Data Structures

by samtregar (Abbot)
on Jun 18, 2002 at 18:00 UTC ( #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!)


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2023-03-25 07:32 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (62 votes). Check out past polls.