Gossamer Forum
Home : General : Perl Programming :

using templates

Quote Reply
using templates
Hi
I want to use a footer.txt and header.txt in script to display all the top and bottom HTML and so it would be easier to change it.

I want to be able to change the title.

sub top {
open(HEADER,"$headerfile");
@header = <HEADER>;
close(HEADER);
print "@header\n";
}

So I call it @top("The title i want");

and the txt contains \<title\>$_[0]\</title\>

It doesn't work and the page is displayed with title "$_[0]" any suggestions how i can change the title??

------------------
---------------
Greg L
gregl@email.com
Quote Reply
Re: using templates In reply to
How about:

sub top {
my $title = shift;
open (HEADER, $headerfile) or die "Can't open '$headerfile'. Reason: $!";
my $header = join ("", <HEADER&gt Wink;
close HEADER;
$header =~ s,<title>[^<]+</title>,<title>$title</title>,i;
return $header;
}

Then you can do:

print &header('Page1');
print &header('Page2');

You should really cache the results of the header if you are going to be doing it multiple times, but that's another question.. =)

Cheers,

Alex