MistaMuShu has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks!
After a long hiatus from the site, I'm back again :)
I've been toying with a side pet project for publishing HTML files. What I'm trying to achieve is similar to what ActionView, and other templating tools do.
In publish.pl, let's say I have a subroutine 'layout' that has local variables $headline, $body, $url. Within this sub, I'd like to call another script 'article.layout.pl', but with the local variables $headline, $body, and $url available to the script. 'article.layout.pl' would then use these variables to print out the final layout.
In publish.pl
sub layout { ... my ($headline, $body, $url); ... # call article.layout.pl ??? article.layout.pl {$headline, $body, $url}; }
In article.layout.pl
print <<HEADER ... HEADER print $title; print $body; print $url; print <<FOOTER ... FOOTER
I realize I could use TemplateTookit to achieve this, but I was hoping to learn how to call mess with perl scoping in general.
Thanks fellow monks! It's good to be back.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Injecting local variables into a template
by hipowls (Curate) on Feb 06, 2008 at 05:45 UTC | |
Re: Injecting local variables into a template
by ikegami (Patriarch) on Feb 06, 2008 at 06:53 UTC | |
Re: Injecting local variables into a template
by wfsp (Abbot) on Feb 06, 2008 at 06:13 UTC |