programmer.perl has asked for the wisdom of the Perl Monks concerning the following question:
Hi everyone,
I wrote a module House.pm and I save it in a directory /home/hamidjon/Perl/Learning/code_examples/myModules
The script of a House.pm is:
package House; # Class sub new { # Class method called a constructor my $class = shift; my $ref={ "Owner"=>undef, # Attributes of the object "Price"=>undef, # Values will be assigned later }; bless($ref, $class); # $ref now reference an object in this class return $ref; # A reference to the object is returned } 1;
To use this module I'm adding this line to my program: use lib ("/home/hamidjon/Perl/Learning/code_examples/myModules");
Am I doing right by adding this line? Are there any other (most correct) ways to use? What does mean the code line: unshift(@INC, "directory"), first I used unshift(@INC, ""); method but it didn't work, then I used 'use lib ("directory");' and it worked, is it true? Thank you...
Code of program that uses the House.pm module:
#!/usr/bin/perl -w use lib ("/home/hamidjon/Perl/Learning/code_examples/myModules"); use House; my $houseref = House->new(); print "\$houseref in main belongs to class ", ref($houseref), "\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: using the Modules
by zentara (Archbishop) on Jul 15, 2012 at 13:04 UTC | |
Re: using the Modules
by CountZero (Bishop) on Jul 15, 2012 at 17:47 UTC | |
Re: using the Modules
by Anonymous Monk on Jul 15, 2012 at 13:08 UTC | |
by frozenwithjoy (Priest) on Jul 15, 2012 at 16:36 UTC | |
by programmer.perl (Beadle) on Jul 16, 2012 at 05:11 UTC | |
by programmer.perl (Beadle) on Jul 16, 2012 at 12:51 UTC | |
Re: using the Modules
by cavac (Parson) on Jul 15, 2012 at 22:12 UTC |
Back to
Seekers of Perl Wisdom