in reply to hash substitution in regex

Just a general comment:

I use perl to generate html pages and content within them, with a templating system that I have been doggedly improving over the course of events.

I'm just curious: why? To improve your Perl, or because you actually need a templating system? If it's the former, that's a worthwhile and commendable endeavor, but if it's the latter, I'd recommend against reinventing the wheel; there's various powerful and/or mature templating systems available, or so I'm told.

Replies are listed 'Best First'.
Re^2: hash substitution in regex
by Aldebaran (Curate) on Aug 18, 2014 at 08:10 UTC

    There's a lot to say here. The fact is, I'm still learning, and part of the learning process is re-working what you have. There isn't anything broken about this routine, for example, but writing the header to an html page is not the fancy part of this evolving toolset. As I'm now working through the Alpaca book, I want to try fancier things with language than what I can find here. Furthermore, I don't understand something until I've re-written it a few times....

    sub write_header { use strict; use Text::Template; my $rvars = shift; my %vars = %$rvars; # get time my $now_string = localtime; $vars{"date"} = $now_string; my $header = $vars{"header"}; my $template2 = Text::Template->new(SOURCE => $header) or die "Couldn't construct template: $!"; my $result2 = $template2->fill_in(HASH => \%vars); return \$result2; }

    I also wrote a utility script that clones the template and imports data, so that I'm not betting the whole house every time a few lines change here or there. Always curious to hear what works for other people.