> You can already do this with tpage:
>
> #!/usr/local/bin/tpage
> <html>
> [% somettdirective %]
> </html>
> 

I tried this and it didn't work.  Maybe I'm missing something.  But I
think it's because tpage won't

 a) remove #!/usr/local/bin/tpage from the top of the file
 b) send out Content-Type: text/html\n\n first

So I get to thinking that this Template stuff shouldn't be that hard, and
there's good documentation, and I have the source to tpage, so I'll write
my own version.

So I wrote this, and saved it at /usr/local/bin/wtpage

------------------------------------------------------
#!/usr/local/bin/perl -w

use strict;
use Template;

# get the filename of our file
my $file = $ARGV[0];

# open the file 
open (FILE, $file) or die "File $file not there!";

# eat the line with the command '#!/usr/local/bin/wtpage' on it
<FILE>;

# print out the standard header
print "Content-Type: text/html\n\n";

# create a template processor 
my $template = Template->new({
    ABSOLUTE => 1,
    RELATIVE => 1,
});

# we're dealing with this file
$template->process(\*FILE)|| die $template->error();

------------------------------------------------------

And then this as a source file

------------------------------------------------------

#!/usr/local/bin/wtpage

<html>
<head><title>Hello mum</title></head>
<body>
[% FOREACH bottles = [10,9,8,7,6,5,4,3,2,1] %]
<p>
[% bottles %] green bottles hanging on the wall,<br>
[% bottles %] green bottles hanging on the wall,<br>
If one green bottle were to accidentally fall,<br>
There'd be [% bottles - 1 %] bottles hanging on the wall.
</p>
[% END %]
</body>
</html>

------------------------------------------------------

Which works fine from the command line, producing

http://2shortplanks.com/template/bottles.txt

Hooray, I think, so I try it from apache... but fails horribly, dumping
this in the log.  Any idea why this might be?

[Fri Nov 24 12:38:41 2000] [error] (8)Exec format error: exec of
/virtual/twoshortplanks.com/www/html/template/test.cgi failed
[Fri Nov 24 12:38:41 2000] [error] [client 213.86.6.77] Premature end of
script headers: /virtual/twoshortplanks.com/www/html/template/test.cgi

I asked Leon (as he set up that apache) but he had no idea.

Any concept of what I'm doing wrong here?  I have the feeling I'm being
very very stupid and overlooking something...

Later.

Mark

-- 
print "\n",map{my$a="\n"if(length$_>6);' 'x(36-length($_)/2)."$_\n$a"} (
   Name  => 'Mark Fowler',        Title => 'Technology Developer'      ,
   Firm  => 'Profero Ltd',        Web   => 'http://www.profero.com/'   ,
   Email => '[EMAIL PROTECTED]',   Phone => '+44 (0) 20 7700 9960'      )





Reply via email to