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";
In reply to using the Modules by programmer.perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |