PDA

View Full Version : Include Files with Perl?



Christopher
April 25th, 2002, 07:57
Is there a way to include files with Perl?

Like a HTML file, similar to the PHP function include()


Thanx

ashben
April 25th, 2002, 12:11
To include & execute another server-side script, use:

<!--#exec cgi="scriptname.cgi" -->

To include the contents or output of a static file, use:

<!--#include file="header.html" -->

Christopher
April 25th, 2002, 12:49
Thanx

Dusty
April 25th, 2002, 16:35
Are you talking about including a Perl script's output from an HTML file or including a file from within a Perl script?

Christopher
April 25th, 2002, 17:46
Well I want to be in a perl script and have something like:


print "Content-type: text/html\n\n";
print "MY HONKING BIG HTML HEADER HERE";
print "My Text";
print "MY HONKING BIG HTML FOOTER HERE";

So, could I go like this:


print "Content-type: text/html\n\n";
print "<!--#include file="header.html" -->";
print "My Text";
print "<!--#include file="footer.html" -->";[/

Or is there a different way?

YUPAPA
April 25th, 2002, 19:26
#!/usr/bin/perl
use strict;
use Fcntl qw(:DEFAULT :flock);

my $file = qq(myfile.txt);

print "Content-Type: text/html\n\n";

sysopen(FILE,$file,O_RDONLY) || die print "Could not open $file for READ\n";
while(<FILE>) {
my $line = $_;
chomp $line;
print "$line\n";
}
close(FILE);

YUPAPA
April 25th, 2002, 19:28
replace "myfile.txt" on line 5 with your filename. :)

Christopher
April 25th, 2002, 22:17
Wow, thats kinda complicated, isn't there a way to just write it simply?

Dusty
April 25th, 2002, 22:23
open(FILE,"file.txt");
print <FILE>;
close(FILE);

or you could put it all on one line

open(FILE,"file.txt");print <FILE>;close(FILE);

Better?

Christopher
April 26th, 2002, 07:33
Lot better, thanx