Thread CGI und Inhalte wie bei PHP austauschen? (13 answers)
Opened by demonking at 2011-06-08 20:49

GwenDragon
 2011-06-09 10:05
#149530 #149530
User since
2005-01-17
14563 Artikel
Admin1
[Homepage]
user image
PHP wird ja oft als nix anders wie eine große Templatemaschine für HTML verwendet.
Klappt mit Perl auch.

Du verwendest CPAN:HTML::Template oder CPAN:HTML::Template::Compiled oder CPAN:EmbPerl oder CPAN:HTML::Mason um Inhalte mit Perl dynamisch zu ändern.

Ungetestetes Beispiel (HTML::Template::Compiled):
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use strict;
use warnings;

use HTML::Template::Compiled;
use CGI;

my $cgi = CGI->new();

my $time = localtime(time);

my $template = <<HTML;
<html>
<body>
<table>
<tr>
<td>Blah ist $time</td>
<td><?if k ?>Key ist <?= k ?><?/if k ?></td>
<td>Blubb</td>
</tr>
</table>
</body>
</html>
HTML

my $htc = HTML::Template::Compiled->new(
    tagstyle => [qw/+php/],
    scalarref => \$template,
    cache => 0,
);

$htc->param(
    k => $cgi->param('key'),
);

print $htc->output;






Editiert von GwenDragon: Code getestet + getauscht
Last edited: 2011-06-09 10:35:01 +0200 (CEST)
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

View full thread CGI und Inhalte wie bei PHP austauschen?