Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > include files with Perl

Reply
Thread Tools

include files with Perl

 
 
Dan P
Guest
Posts: n/a
 
      07-13-2004
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
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-13-2004
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
 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      07-13-2004
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 <(E-Mail Removed)>
"Software is like sex: It's better when it's free." (Linus Torvalds)
 
Reply With Quote
 
David Magda
Guest
Posts: n/a
 
      07-13-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      07-15-2004
David Magda <(E-Mail Removed)> writes:

> (E-Mail Removed) (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\\
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl? PerlFAQ Server Perl Misc 0 03-09-2011 11:00 PM
FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl? PerlFAQ Server Perl Misc 0 02-11-2011 05:00 AM
Perl / cgi / include file a la #include me Perl Misc 10 03-26-2010 10:21 PM
include files in perl daniel kaplan Perl 2 12-18-2009 08:07 PM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM



Advertisments