Perl simple Template function

If make a simple example to translate the hompage with a template.

use strict;
#example html
my $html = q(

#translate german
my %GER = (
    T1 => 'Uberschrift',
    T2 => 'Inhalt',

#translate english
my %ENG = (
    T1 => 'Title',
    T2 => 'Content',

print interpolate($html,%GER).$/;
print interpolate($html,%ENG).$/;

sub interpolate {
    my ($var,$hash) = @_;
	foreach my $search (sort {length($hash->{$a}) <= length($hash->{$b})} keys $hash) {
		$var =~ s!(@$search@)!$hash->{$search}!g;
	$var =~ s!(@.{1,}@)!?!go;

The HTML code result looks like this:



in the Browser it looks like this:







One thought on “Perl simple Template function”

  1. My brother suggested I may like this website. He
    was once totally right. This put up truly made my day.
    You can not imagine just how so much time I had spent for this info!
    Thank you!

Leave a Reply

Your email address will not be published.

3 × 2 =