include files with Perl

Discussion in 'Perl Misc' started by Dan P, Jul 13, 2004.

  1. Dan P

    Dan P Guest

    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
     
    Dan P, Jul 13, 2004
    #1
    1. Advertising

  2. 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/clpmisc/clpmisc_guidelines.html

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jul 13, 2004
    #2
    1. Advertising

  3. Dan P

    Tore Aursand Guest

    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 <>
    "Software is like sex: It's better when it's free." (Linus Torvalds)
     
    Tore Aursand, Jul 13, 2004
    #3
  4. Dan P

    David Magda Guest

    (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
     
    David Magda, Jul 13, 2004
    #4
  5. David Magda <> writes:

    > (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\\
     
    Brian McCauley, Jul 15, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. daniel kaplan

    include files in perl

    daniel kaplan, Sep 17, 2004, in forum: Perl
    Replies:
    2
    Views:
    7,903
    Windex007
    Dec 18, 2009
  2. Danny Anderson
    Replies:
    5
    Views:
    530
    Victor Bazarov
    Aug 15, 2003
  3. Andreas Bogenberger
    Replies:
    3
    Views:
    1,011
    Andreas Bogenberger
    Feb 22, 2008
  4. Henry Law
    Replies:
    3
    Views:
    1,024
    Henry Law
    Jul 22, 2004
  5. me
    Replies:
    10
    Views:
    1,012
    ccc31807
    Mar 26, 2010
Loading...

Share This Page