Other than the require method suggested, you might also want to think about making a 
pure perl module.  It's not that hard, and it makes it much easier to copy the code to 
other computers if you ever want to.  Here's an example of a simple module:
 
#################################
#  Sample.pm
package Tim::Sample; #assumes the file is at .../site/lib/Tim
sub InsertSpaces{
  my @text = split //,$_[0]; #get characters of function parameter
  return join(' ',@text);
}
1
#################################
 
Don't forget that the last line should evaluate to TRUE.  That's why I put a 1 on a 
line by itself.  It will fail if you forget.  If you save the code above into a file 
called Sample.pm and save it into your lib directory (usually [perldir]/site/lib) in a 
folder called Tim, then you can make a script like this:
 
#################################
use strict;
use warnings;
use Tim::Sample;
my $string = "word";
print Tim::Sample::InsertSpaces($string);
#################################
 
I find that it's easier to keep track of this way, too, because  you don't have to 
worry about changing the location of your files and having to edit a bunch of scripts 
and the like.  Of course at this level, it doesn't really make THAT much of a 
difference...

        -----Original Message----- 
        From: r huber [mailto:[EMAIL PROTECTED] 
        Sent: Sun 1/4/2004 6:18 PM 
        To: [EMAIL PROTECTED] 
        Cc: 
        Subject: Making A Library of Perl Subroutines
        
        

        I am writing several subroutines that I want to make
        available to other programs without directly including
        the code in those programs. Can anyone explain how to
        do this or where to go to find out how to do it.
        

Reply via email to