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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.