Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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!)


In reply to Re: Complex Data Structures by samtregar
in thread Complex Data Structures by random

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?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2023-06-01 05:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found