Mat Harris wrote:
> i would reall like to start creating my own modules for all those
> regularly used bit and pieces, but i don't know where to start. i have
> read perldoc perlmod and sources of loads of other modules but nothing..
>
> if i laid down a small scenario, could someone help me modulise it so i
> can get my head round?
>
> cheers
>
creating simple useful module for bits and pieces is not hard. let say, i
want to build a module that has two functions in it. one function will
returns the string 'hello world' and another function returns the string
'hi world'. i created a module call 'Greeting.pm' and i do the following:
#!/usr/bin/perl -w
package Greeting; #-- name of my module
use strict;
use Exporter;
our @ISA=qw(Exporter);
#-- i want other script to be able to use the following functions:
#-- hello()
#-- hi()
our @EXPORT=qw(hello hi);
sub hello{
return 'hello world';
}
sub hi{
return 'hi';
}
1; #-- success
__END__
and then in another script like test.pl:
#!/usr/bin/perl -w
use strict;
use Greeting; #-- use the module we created above
print hello,"\n"; #-- calls the hello() functin in Greeting.pm
print hi,"\n"; #-- calls the hi() function in Greeting.pm
__END__
prints hello world and hi world to the screen. as you can see, creating
simple modules like this is not hard. there is a lot more to that but the
basic idea is the same. if you don't know what @EXPORT, use Export, @ISA is
all about, you might need more reading. :-)
david
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]