PDA

View Full Version : Including a file in Perl



Robert
November 12th, 2000, 11:34
Hi All...

I have a banner ad system and I would like to include the file 'ad.pl' in a perl script. I use the (? virtual("./cgi-bin/ad.pl") ?) (replace () with <> ) command for PHP but would like to know what the same command is for perl? So I can include the ad.pl script in my perl scripts. Any ideas?

Thanks!

-Rob

KapTinKiRk
November 12th, 2000, 12:16
Not that I know perl (my book is on its way, heh). But at the top of the script put a line like this.

require "ad.pl";

And if it is not in the same directory, then you would put the path to ad.pl

Robert
November 12th, 2000, 12:19
I don't think that's it but thanks for trying.

KapTinKiRk
November 12th, 2000, 12:23
If you are including the banner script much like, including an ad script into a HTML file, the code is:

<!--#include virtual="/cgi-bin/ad.pl"-->

If thats not what your looking for then KiRk doth not know.

Nick
November 12th, 2000, 13:33
Kirk, that will only work if the server parses stuff in a CGI script like HyperMart does....

KapTinKiRk
November 12th, 2000, 13:39
I don't even know what robert is asking anymore :(

To include a perl script into another one, you use 'require'.. no?

And for including scripts into a HTML file such as banners, polls etc. then you use the 'include virtual' or 'exec cgi' tag...no?

If not then I'm retarded :p

Nick
November 12th, 2000, 15:30
I think he wants to use a sever call in a CGI generated page and wants to use SSI or PHP in the cgi script which generates the HTML page.

Pretty confusing, huh? :p

KapTinKiRk
November 12th, 2000, 16:11
Hmm, so he wants the CGI script to generate a HTML page, and that page to have SSI tags in it. So then it WOULD be the include virtual tag, just that it's not supported by a lot of hosts.

I have a script that does the same, and has SSI tags. And it works, except its on Virtualave at the moment while I test everything out, so I guess thats why it works now. (btw, thats the plasticsword.com site, theres a link on the main page to the script in question)

Though my other site, 3wrestle.com has a similar script, and to include simple text files I used this code.

open (FILE,"/path/to/file.txt");
@file = <FILE>;
close(FILE);
foreach $line (@file) {
print "$line";
}

Theres probably another way to do it, but... my Perl book is still in the mail, silly Amazon.com :p

Also, in the documentation for WebAdverts (dunno if this is what you are using) it says for including ads.pl into CGI scripts, the code should be:

print "<P>Stuff to appear above the banner.\n";
print "<CENTER><P>\n";
$ADVNoPrint = 1;
$ADVQuery = "";
require "/full/path/to/ads.pl";
print "</CENTER>\n";
print "<P>Stuff to appear below the banner.\n";



WebAdverts Documentation
"The $ADVNoPrint variable is an addition necessary in this case to suppress the printing of the "content type" line; the $ADVQuery null definition will ensure there are no conflicts between WebAdverts and any QUERY_STRING info your other script may use.)"

atlas
November 12th, 2000, 22:41
Yeah, I don't know what he's asking either. I'm guessing he wants


require thing.pl;


Make sure thing.pl ends with '1;'

Also, don't use file slurps unless you need to:



open(FILE,"/path/to/file");
while( <FILE> ) { print $_; }
close(FILE);



Will use less memory, and is generally a better idea.

mjk@atlascgi.com