As a novice in perl I realize that it’s a bit presumptuous for me to attempt references and complex data structures. But I had a need and gave it a shot — a failing shot. I’ve been fiddling with my failure, almost mindlessly, all weekend; now I need some help.
Below is the template segment I am trying to populate with data, and following it is the segment of code that attempts to call it. The output I get in my browser is persistently empty, with every instance of [% %] being replaced with banks.
start HTML ------------<table>[% FOREACH course IN courses %]
<br><br>
<h2 id="[% course.cat_abbr %]">[% courses.category %]</h2><br><br>
<table> <caption> [% course.caption %] </caption>
<!-- LEVEL 4 -->
<tr style="background-color: Plum">
<td>L4 (HN)</td>
<td><input type="checkbox" name="course_file"
value="[% course.title %]_q1l4v[% courses.version %]"> 1-4</td>
my ( $cat_abbr, $category, $title, $caption, $version ); # for Template
my ( @courses, $string ); # for calculating
while ( my $line = <DATA> ) {
( $cat_abbr, $category, $title, $version ) = split /\t/, $line;
chomp $version;
$caption = $title;
$caption =~ s{_|\-}{ }xmsg; # replace _ and - with space
$caption =~ s{\b(\w)}{\U$1}g; # impose simple titlecase
$caption = "$caption" . ' (version ' . "$version" . ')';
push @courses,
{
cat_abbr => $cat_abbr,
category => $category,
caption => $caption,
title => $title,
version => $version,
}
}
my %list = (list => \@courses);
# Call Template Toolkit
local $| = 1; # auto flush buffer
my $path = "/big/dom/x$server/www/templates";
my $tt = Template->new(
{INCLUDE_PATH => "$path"}
print "Content-Type: text/html\n\n";
$tt->process($input, $vars)
or die $tt->error();
On Oct 30, 2018, at 12:40 PM, Shlomi Fish <shl...@shlomifish.org> wrote:Hi Rick,
On Tue, 30 Oct 2018 07:34:11 -0500
Rick T <pe...@reason.net> wrote:Uri, thanks for the boatload of useful suggestions! I will am busying myself
with understanding and applying them.
Regarding Template::Simple, this module isn’t among the many that my host has
installed, and I have not had success trying to learn how to install stuff
from CPAN. Fortunately I’m beginning to get the hang of Template Toolkit, and
I may need it for more complex situations that come up. Switching from
HTML::template this year was a challenge, and I had to rewrite a lot of my
perl to go with it. I know that most perl people are good at using the CPAN
resource, but I’m just a high school teacher who dabbles in perl. And at age
74 I have to be choosy about which learning curves I take on!
Still, if anyone can point me to a “beginners guide” to using CPAN, I’ll take
a look at it.
On Oct 30, 2018, at 1:41 PM, Brandon McCaig <bamc...@gmail.com> wrote:
On Tue, Oct 30, 2018 at 07:34:11AM -0500, Rick T wrote:Still, if anyone can point me to a “beginners guide” to using
CPAN, I’ll take a look at it.
The easy button for CPAN, or at least the one I'm most familiar
with, is cpanm AKA App::cpanminus. The cpan command is very
low-level and prompts the user repeatedly, making it basically
unusable by a human user. If it is available to you, or you're
able to get it installed, cpanm takes away all of this pain and
automatically fetches, builds, tests, and installs your desired
package and all of its dependencies automatically.. You'd just
invoke:
$ cpanm Template::Simple
And with minimal output it should install for you. If not, you
might have to get your hands dirty reading logs to figure out
what is wrong, and what to do about it, but for well maintained
packages in a Unix-like environment that is rare in my
experience..
You can read about cpanm and how to install it from the Git repo
readme:
https://github.com/miyagawa/cpanminus/tree/devel/App-cpanminus
I have not used hosting environments for Perl deployment so I
cannot say whether this is likely to be an option for you.
On another note, a nice way to control your Perl environment is
by using perlbrew, which allows you to install an up-to-date perl
distribution within your home directory to use, and to likewise
install your CPAN modules within your home directory too. It is
also capable of managing many different perl environments
side-by-side which probably isn't needed, but doesn't hurt to
know about..
I'm not sure how difficult it would be to use a perlbrew
environment for your hosting environment, but nevertheless it is
a useful resource to know about. Note that if you do use perlbrew
it has a command to install cpanm too so it might kill two birds
with one stone.
Regards,
--
Brandon McCaig <bamc...@gmail.com> <bam...@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bambams.ca/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
Uri, thanks for the boatload of useful suggestions! I will am busying myself with understanding and applying them.
Regarding Template::Simple, this module isn’t among the many that my host has installed, and I have not had success trying to learn how to install stuff from CPAN. Fortunately I’m beginning to get the hang of Template Toolkit, and I may need it for more complex situations that come up. Switching from HTML::template this year was a challenge, and I had to rewrite a lot of my perl to go with it. I know that most perl people are good at using the CPAN resource, but I’m just a high school teacher who dabbles in perl. And at age 74 I have to be choosy about which learning curves I take on!
Still, if anyone can point me to a “beginners guide” to using CPAN, I’ll take a look at it.
Rick Triplett