Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   include files with Perl (http://www.velocityreviews.com/forums/t887256-include-files-with-perl.html)

Dan P 07-13-2004 08:41 PM

include files with Perl
 
Can you create an include file in perl, filled with subs that require
parameters and then call the appropriate function from the file while
passing in your parameters from your main program. I read
documentation on require and use, but I can't seem to get it working
right.

thanks for your help

Gunnar Hjalmarsson 07-13-2004 08:50 PM

Re: include files with Perl
 
Dan P wrote:
> Can you create an include file in perl, filled with subs that
> require parameters and then call the appropriate function from the
> file while passing in your parameters from your main program.


Yes, of course. In Perl 5 such files are normally called modules, and
have the file extension .pm.

> I read documentation on require and use, but I can't seem to get it
> working right.


What have you tried? Please post some code.

If you are new in this group, it's a good idea to first read the
posting guidelines:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Tore Aursand 07-13-2004 08:53 PM

Re: include files with Perl
 
On Tue, 13 Jul 2004 13:41:24 -0700, Dan P wrote:
> Can you create an include file in perl, filled with subs that require
> parameters and then call the appropriate function from the file while
> passing in your parameters from your main program. I read documentation
> on require and use, but I can't seem to get it working right.


You want to create modules;

perldoc perlmod


--
Tore Aursand <tore@aursand.no>
"Software is like sex: It's better when it's free." (Linus Torvalds)

David Magda 07-13-2004 09:29 PM

Re: include files with Perl
 
danielpinsky@hotmail.com (Dan P) writes:

> Can you create an include file in perl, filled with subs that
> require parameters and then call the appropriate function from the
> file while passing in your parameters from your main program. I


I've used do(). So if you have a main.pl and your common sub-routines
are in subs.pl you could do a:

do "subs.pl";

--
David Magda <dmagda at ee.ryerson.ca>, http://www.magda.ca/
Because the innovator has for enemies all those who have done well under
the old conditions, and lukewarm defenders in those who may do well
under the new. -- Niccolo Machiavelli, _The Prince_, Chapter VI

Brian McCauley 07-15-2004 05:00 PM

Re: include files with Perl
 
David Magda <dmagda+trace040423@ee.ryerson.ca> writes:

> danielpinsky@hotmail.com (Dan P) writes:
>
> > Can you create an include file in perl, filled with subs that
> > require parameters and then call the appropriate function from the
> > file while passing in your parameters from your main program. I

>
> I've used do(). So if you have a main.pl and your common sub-routines
> are in subs.pl you could do a:
>
> do "subs.pl";


Yeah, but it would still be worth investing a few extra minutes to
understand modules.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\


All times are GMT. The time now is 02:42 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.