including or calling another perl script that has common code/functions

including or calling another perl script that has common code/functions

am 05.09.2005 21:49:06 von Hendry Taylor

I would like to have a Perl script that has some common functions etc
and then call it from other Perl scripts. This common Perl script may
return an array or a number of values depending on the function.

Currently I am using "require" and it works, but I am not sure if that
is the most efficient way of doing it. One problem I have found with the
require way of doing it is that it seems to loose my first value
returned if i return numerous values at the same time.

Re: including or calling another perl script that has common code/functions

am 05.09.2005 23:31:01 von Jim Gibson

In article , Hendry
Taylor wrote:

> I would like to have a Perl script that has some common functions etc
> and then call it from other Perl scripts. This common Perl script may
> return an array or a number of values depending on the function.

Your "script" should not return anything but a true value if you are
using "require". The functions in the script, however, may return any
number of arguments.

>
> Currently I am using "require" and it works, but I am not sure if that
> is the most efficient way of doing it. One problem I have found with the
> require way of doing it is that it seems to loose my first value
> returned if i return numerous values at the same time.

You should be calling "require" only once on your script file. You
should not be saving the return value from the require, as the return
value is an indication to the Perl compiler whether or not the require
was successful. This is best done by putting a bare "1;" at the end of
the script.

Having executed a "require script.file" statement, you may then call
any subroutines defined by script.file as if they had been defined by
your program. Calling "require script.file" a second time will do
nothing, as the runtime will ignore the call.

See "perldoc -f require" for details.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com