in reply to Re: Getting data ready for HTML::Template
in thread Getting data ready for HTML::Template

Thanks unforgiven. Your untested(but valuable) code gave me a piece that I was wondering about(incrementing the hash key) and allowed me to see that at least I'm doing the basics correct because it got me a bit further. I made the suggested changes plus changed my template slightly like this:
<table border="1"> <tr> <TMPL_LOOP NAME=THIS_LOOP> <td> <TMPL_VAR NAME="MACHINE"> </td> <td> <TMPL_VAR NAME="key1"> </td> <td> <TMPL_VAR NAME="key2"> </td> <td> <TMPL_VAR NAME="key3"> </td> </tr> </TMPL_LOOP> </table>

New output:

Machine Key One Key Two Key Three
machine3 value7 value8 value9
machine3 value7 value8 value9
machine3 value7 value8 value9

Now it seems like I just need to figure out the correct logic in my loop that creates the data.

Replies are listed 'Best First'.
Re^3: Getting data ready for HTML::Template
by jethro (Monsignor) on Nov 18, 2009 at 22:37 UTC
    The remaining problem is that you push \%row_data into your array, which is the same pointer to the same data structure (which gets written to three times until only the last row data remains) instead of a new one. The easiest way to generate a new hash every time through the loop is to change the third line of Unforgivens loop
    %row_data = ();
    to
    my %row_data = ();
      Awesome! Thanks for these solutions. It's now working to the point where I can figure out the rest because it's just formatting.

      Machine Key One Key Two Key Three
      machine1 value1 value2 value3
      machine2 value4 value5 value6
      machine3 value7 value8 value9

      Here's the final segment of code:

      Thank you for the help!
        Could you also provide the code for the template?

        What exactly is your problem? Do you want the table headings aligned with the data? If yes, why the heck do you put headings and data into two completely independent tables? Use a single table. As a side note, get rid of the border attribute and use CSS instead.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Gah, I knew I was forgetting to mention something else. Thanks for catching that.

      It's an example of keeping your variables close to where they're used. For most cases, it's better to declare a variable, use it, then stop using it. If nothing else, when reading your code, it makes it easier to keep all those variables you're actively using in your head, since as soon as you're done with it, you can forget about it.