• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Including a file in Perl

Robert

NLC
NLC
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
 
Not that I know perl (my book is on its way, heh). But at the top of the script put a line like this.
Code:
require "ad.pl";

And if it is not in the same directory, then you would put the path to ad.pl
 
If you are including the banner script much like, including an ad script into a HTML file, the code is:
Code:
<!--#include virtual="/cgi-bin/ad.pl"-->

If thats not what your looking for then KiRk doth not know.
 
Kirk, that will only work if the server parses stuff in a CGI script like HyperMart does....
 
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
 
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
 
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.
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:
Code:
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.)"
 
Yeah, I don't know what he's asking either. I'm guessing he wants
Code:
require thing.pl;

Make sure thing.pl ends with '1;'

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

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

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

mjk@atlascgi.com
 
Back
Top