And, it's worth mentioning a couple of things.

If your module and the script that's using it are in the same directory, you don't need use lib. However, if you run it like this:

C:\> perl C:\test\testbvt\hello.pl

Perl sees C:\ as the current directory, and so can't find the modules. If you cd to C:\test\testbvt first, it should work. If this is the type of situation you have, you are wiser not to use lib, but to specify:

C:\> perl -IC:\test\testbvt C:\test\testbvt\hello.pl

The I option specifies a dir to add to @INC for that run only.

On the other hand, if you have the following files:

C:\test\hello.pl C:\test\Lib\Hello.pm

You might want to change your package name to Lib::Hello instead of just Hello. Definitely read the docs for lib and perlmod, which cover how modules are located and how @INC works.

Two quick last points. First, perl modules are not 'scripts': therefore you don't need (and probably shouldn't use) the #!/usr/bin/perl line in them. That line is a UNIX thing that lets the shell know to invoke the Perl interpreter for the file in question. By the time you import a module, the interpreter is working (not the shell).

Second, make a habit of including use strict; use warnings; at the top of scripts and modules until you understand when they can/should be turned off. If you get warnings you don't understand, add use diagnostics; as well, which give a more verbose explanation.

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

In reply to Re^2: Creating new perl modules. by radiantmatrix
in thread Creating new perl modules. by nisha

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.