What is the Simplest way to move Subs to Modules?

G

Great Deals

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?
 
A

Anno Siegel

Great Deals said:
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
 
H

Helgi Briem

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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top