Gossamer Forum
Home : General : Perl Programming :

Library Script

Quote Reply
Library Script
I am trying to write a 'library' script where I can keep all my commonly used sub-routines for all the pages on my site.

The file is called 'lib.pl', and for example, contains a sub-routine called 'header'.

On the script that I want to call the sub-routine, I have 'required' the path to lib.pl.

From the perl script calling the routine I do this:

.
.
require '/path/to/lib.pl';
.
# print header
&header;
.
.

the 'header' script looks like:

sub header {
print qq~
#header html here
~;
}

problem: it is not working. Any idea what I am doing wrong?
Quote Reply
Re: Library Script In reply to
Lee,

How have you set up lib.pl? I ask this because I've made the mistake in the past of setting up the library as a cgi script, which the path to perl, etc. With a library file like this, you don't need the path to perl and you must have:

1;

right at the bottom of the file, which returns true to the main script (or something like that, I'm not up on the intracacies Smile).

If not, you'll probably have to post more of the script here or on your server with a .txt extension, so we can look at it, because what you posted should work ok.

The only other thing I can think of is that maybe you need double quotes on the require, but I never really found out the difference between single and double quotes, so I'm not sure.

Think I might just go and find out actually...

Cheers,
adam
Quote Reply
Re: Library Script In reply to
Well, I have it set up like a cgi, I have the path to perl, and it doesn't end in 1;

Sounds like I have a few things going against me. I'll give it a try and thanks for the input!

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