using a separate module is a good idea in this kind of situation.

Put your subroutine to a separate file with the following format:

package packagename;

sub blaa {

code...code...code...

}

1; # So that the module will return a true value

__END__


Save this as packagename.pm and that's it.

Then to your main script you need to get this module included like:

use lib qw(path/to/your/module);
use packagename;

Then in your code you can access your good 'ol subroutine like this:

packagename::blaa();

or you can pass some argumenst into it as well:

packagename::blaa($argument);

etc. You probably get the picture.

A word of warning: I'm also a newbie, so if there were some errors in my
explanation, I'd be grateful to hear about it!

Cheers,

Joni


-----Original Message-----
From: Ken Cole [mailto:[EMAIL PROTECTED]]
Sent: 20 July 2001 03:29
To: perl. org Beginners
Subject: I need to create a module - I think - and don't know how


Hi everyone,

I am starting to write a number of perl programs.  Most relate around a
particular application which has numerous environmental variables.  The
variables can be set from a number of places and those places have a
hierarchy as to which takes precedence over the others.

I have therefore written a perl sub routine that builds up a hash of
environmental variables and their respective values and then use them in
my scripts.

I no longer want to maintain this sub routine in every script I write
regarding this application.

Do I need to create a module and put this routine in it?

If so how?

Do I declare it as a function in the module and then call it from my
other scripts?

All help as usual gratefully appreciated.

Ken Cole


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to