Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Populating an HTML Template

by injunjoel (Priest)
on Mar 28, 2006 at 00:15 UTC ( #539591=note: print w/replies, xml ) Need Help??

in reply to Populating an HTML Template

Though there are many things that could be suggested about your code the most important is to adopt the use of strict and warnings.
Other than that I get the feeling you have not provided all of the relevant code in the example you give.

For instance where do %loop_data and $loop_data get initialized? What is suppose to happen to ($name,$value) in your
foreach $line (@allow_edit){ .... }
I think I follow what you are attempting up until you close your filehandles... Then things get murky.

Empirically @loop will never hold anything since you never fill it. Your #fill in the loop, foreach block creates and fills in $name and $value that fall out of scope with each iteration, @loop is never involved.
Now if I follow your intent, and this is a big stretch to say the least, here is my suggestion for what I think you are shooting for (However not having seen your HTML template its a guess at best).

Untested mind you.
my @loop; #fill in the array @loop with hash references from @allow_edit... foreach (@allow_edit){ my($name, $value) = split /=/,$_; push @loop, {$name=>$value}; }
Then continue with your template calls.
It would be helpful to see what the markup (HTML) looks like that you are filling with "loop" in your $template->param call.
without that everything is simply a shot in the dark.

Okay, thats definitely helpful.
So given the code.
<!-- start of loop --> <TMPL_LOOP NAME="loop"> <tr> <td align="right"><TMPL_VAR NAME="part1"></td> <td><INPUT TYPE=text NAME="<TMPL_VAR NAME="par +t1">" VALUE="<TMPL_VAR NAME="part2">"></td> </tr> </TMPL_LOOP> <!-- end of loop -->
I am lead to think you would like $name to appear in "part1" and $value to appear in "part2". Am I getting warmer?
Lets modify the loop I suggested earlier to accomplish this.
my @loop; #fill in the array @loop with hash references from @allow_edit... foreach (@allow_edit){ my($name, $value) = split /=/,$_; push @loop, {part1=>$name, part2=>$value}; }
That should do it. I hope that helps.
And one more thing, have a look at the range operators for another way to handle your file partitioning.

"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

Replies are listed 'Best First'.
Re^2: Populating an HTML Template
by hmag (Acolyte) on Mar 28, 2006 at 10:10 UTC
    Hi again, Thanks all who replied - I did just update the SoPW with the Template code after the Perl - hope this helps.
Re^2: Populating an HTML Template
by hmag (Acolyte) on Mar 28, 2006 at 20:24 UTC
    Hi again, Many thanks - I get an undefined parametr now, but will check it out - thanks again.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://539591]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2017-01-21 20:02 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (185 votes). Check out past polls.