What is the Simplest way to move Subs to Modules?

Discussion in 'Perl Misc' started by Great Deals, Sep 24, 2003.

  1. Great Deals

    Great Deals Guest

    I am giving up on writing modules. Too complicated. My only goal is
    too many perl programs can use the same subs. Now, I have to copy and
    pastes those subs into each perl program. Once I do an update, I have
    do re copy paste all over again..

    Please show me the easiest/simplest way to move subs to 1 common file
    to let many programs to share the same subs.

    1 Do I have to include "package" in the pm file?
    2 Do I have to return 1; at the end of the module file?
    3 What is about __END__ should I put # in front of it?
    4 Is there such as include in SSI? so that everytime I run
    something.pl, it will automatically include the sub file?
     
    Great Deals, Sep 24, 2003
    #1
    1. Advertising

  2. Great Deals

    Anno Siegel Guest

    Great Deals <> wrote in comp.lang.perl.misc:
    > I am giving up on writing modules. Too complicated. My only goal is
    > too many perl programs can use the same subs. Now, I have to copy and
    > pastes those subs into each perl program. Once I do an update, I have
    > do re copy paste all over again..
    >
    > Please show me the easiest/simplest way to move subs to 1 common file
    > to let many programs to share the same subs.
    >
    > 1 Do I have to include "package" in the pm file?


    No.

    > 2 Do I have to return 1; at the end of the module file?


    Yes.

    > 3 What is about __END__ should I put # in front of it?


    No. You don't need __END__.

    > 4 Is there such as include in SSI? so that everytime I run
    > something.pl, it will automatically include the sub file?


    "use"

    Anno
     
    Anno Siegel, Sep 24, 2003
    #2
    1. Advertising

  3. Great Deals

    Helgi Briem Guest

    On 24 Sep 2003 02:06:59 -0700,
    (Great Deals) wrote:

    >I am giving up on writing modules. Too complicated. My only goal is
    >too many perl programs can use the same subs. Now, I have to copy and
    >pastes those subs into each perl program. Once I do an update, I have
    >do re copy paste all over again..


    No you don't.

    >Please show me the easiest/simplest way to move subs to 1
    >common file to let many programs to share the same subs.


    Dead simple. Here's the module:

    sub foo { print "Foo\n"; }
    sub moo { print "Moo\n"; }
    1;

    Here's the script that uses it:

    #!perl
    use warnings;
    use strict;
    use lib 'path/to/module';
    use Test_Module;
    moo();
    --
    Helgi Briem hbriem AT simnet DOT is

    Excuse the munged address. My last
    e-mail address was killed by spammers.
     
    Helgi Briem, Sep 24, 2003
    #3
    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. Brent Burkart
    Replies:
    5
    Views:
    792
    Jerry III
    Oct 16, 2003
  2. Alan Silver
    Replies:
    9
    Views:
    2,293
    Alan Silver
    Jun 26, 2005
  3. Alan Silver
    Replies:
    4
    Views:
    3,195
    Alan Silver
    Aug 10, 2005
  4. Guest
    Replies:
    2
    Views:
    548
    Steven Cheng[MSFT]
    Sep 16, 2005
  5. Fendi Baba
    Replies:
    0
    Views:
    348
    Fendi Baba
    Oct 15, 2003
Loading...

Share This Page