On 4/21/05, Daniel Kasak wrote:
> Hi all.
> 
> I have a large script ( 6000 lines ) that I'd like to break into logical
> units. Is there a way I can tell perl to 'append' a list of files into 1
> script so that I can call subs from any of the files and have them
> treated as if they were all from the same script ( ie all my variables
> will be visible )?
> 

It's called a "Perl Module", or .pm file. See:
perlmod             Perl modules: how they work
perlmodlib          Perl modules: how to write and use
perlmodstyle        Perl modules: how to write modules with style

Brief example - say you have a module file called Foo.pm with the
following contents:
####### begin Foo.pm contents
package Foo;
use Exporter qw( import );
@EXPORT_OK = qw(munge);  # symbols to export on request
use strict;
use warnings;
our $VERSION = '0.01';
sub munge {
   print "This is a sub!\n";
}
1;
####### end Foo.pm contents

Now in another script, say use_foo.pl, you write:
####### begin use_foo.pl contents
use strict;
use warnings;
use Foo qw(munge);
print "Foo::VERSION = $Foo::VERSION\n";
munge();
####### end use_foo.pl contents

$VERSION is an example of a variable in Foo.pm accessible from an
external script, and munge() is an example of such a function.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to