develooper Front page | perl.beginners | Postings from July 2003

Re: Need help on modules

Thread Previous | Thread Next
From:
Rob Dixon
Date:
July 31, 2003 04:52
Subject:
Re: Need help on modules
Message ID:
20030731115226.31508.qmail@onion.perl.org

"Pandey Rajeev-A19514" <rajeevpandey@motorola.com> wrote in message
news:C73F06B054B7D6118C040008C7F3613D01E177B5@zin09exm01.corp.mot.com...
> Hi,
>
> I want to create a module, say ABC.pm.
> I dont want to build and install the module.
>
> I want to use a function xyz() of the module ABC in some other script.
> AND, I want to call the function as
> xyz();
> instead of
> ABC::xyz();
>
> Can anyone tell me how to do that without installing the module ?
> Is it sufficient to push the Module path in @INC ?

The current directory '.' is a member of @INC, so if you
simply write your Perl module file in same directory as
the calling program it will work fine (as long as you don't
use a module name that already exists amongst the installed
modules). Try the following files. It should be easy enough
to expand from there to what you want.

** FILE ABC.pm

  package ABC;
  use strict;

  require Exporter;

  our @ISA = qw/ Exporter /;

  our @EXPORT = qw/ xyz /;

  sub xyz {
    print "ABC::xyz() called\n";
  }

** FILE xyz.pl

  use strict;
  use warnings;

  use ABC;

  xyz();

** OUTPUT

  ABC::xyz() called




Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About