On Friday, Nov 14, 2003, at 18:38 US/Pacific, David Inglis wrote:


I have a some code that will be used in a number of my scripts, I know
that if I have  a sub in a script I can call that piece of code as many
times as required from the same script but how do I make this sub
vailable to other scripts I have written.  I imagine that I create a
seperate script with this code and somehow include this or call it.

What you will ultimately want to do is move on to creating your first Perl Module.


I have my general rant on PM's at:


<http://www.wetware.com/drieux/CS/lang/Perl/PM/>

it of course suggests that you visit
<http://www.wetware.com/drieux/CS/Proj/PID/>

where I show how to use h2xs, where it show you at
<http://www.wetware.com/drieux/CS/Proj/PID/#TheTypeScript>
the output of the h2xs and the basic form of a perl
module that it will create.

you will of course want to read

        perldoc perlsub             Perl subroutines
           perlmod             Perl modules: how they work
           perlmodlib          Perl modules: how to write and use
           perlmodinstall      Perl modules: how to install from CPAN


the other strategy is to go with perl's OO-ish approach and that would start out a bit simpler in template form

package Foo::Bar;

        use 5.006;
        use strict;
        use warnings;

our $VERSION = '0.01';

        sub new
        {
                my $type  = shift;
        my $class = ref($type) || $type;
        my $self = {};
        bless $self, $class;

} # end of our simple new

        #---------------------------------
        # so that AUTOLOAD finds one here

        sub DESTROY {}
        
        #
        # your methods here
        #

1; # so that the 'use Foo::Bar' will know we are happy


ciao drieux

---


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



Reply via email to