On Thu, 2009-07-09 at 21:58 -0700, Travis Thornhill wrote: > [File: ./uses_Mod.pl] > #!/usr/bin/perl > > use strict; > use warnings; > > use lib 'Mod';
Not needed. When perl searches for a module, it does so by looking in the directories in @INC (See `perldoc perlvar`). The very last item in @INC is '.', the current directory. However, you may want to add this to all your scripts: use FindBin qw( $Bin ); use lib $Bin; The module, FindBin, is a standard module and comes bundled with perl. What it does is finds the directory where the script is and stores it in $Bin. If your modules are in the same directory, adding $Bin to lib is necessary for your script to work when you run it outside of its home directory. > > use Mod::myMod; This means attach the string 'Mod/myMod.pm' to each of the directories in @INC and see if it's there. perl considers 'Mod' to be a sub-directory and 'myMod.pm' the file. BTW, by convention, pragmatics should start with lowercase letters and modules with uppercase. You should name your modules with names starting in uppercase: Mod/MyMod.pm > > > my $obj = myMod->new(); # <----- THIS IS THE LINE THAT ERRORS > > $obj->myModFunc(); > [end uses_Mod.pl] > > > [File: ./Mod/myMod.pm] > package Mod::myMod; > > use strict; > use warnings; > > require Exporter; > > our @ISA = qw(Exporter); > our @EXPORT = qw(new myModFunc); Exporter is not required. Exporter is used with modules, that is, a file containing a collection of subroutines. It is not needed for objects (unless you are creating a bastardized version that does both, like CGI). > > sub new > { > my $class = shift; > my $self = {}; > > # Just so the constructor does something I can see and verify. > $self->{'time_created'} = time(); > print STDOUT "Object created at " . $self->{'time_created'} . > "\n"; > > bless ( $self, $class ); > return $self; > } > > sub myModFunc > { > my $self = shift; > print "myModFunc called\n"; > } > > 1; > [end myMod.pm] -- Just my 0.00000002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/