in reply to using package functions and vars withouth packagename::

This is an example of where you can use Exporter. The Exporter module allows you to export any functions and even package globals that you care to export from a module to its calling program.

package YourModule; require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(munge frobnicate); # symbols to export on request use ModuleName qw(frobnicate); # import listed symbols frobnicate ($left, $right) # calls YourModule::frobnicate

Dave

Replies are listed 'Best First'.
Re: Re: using package functions and vars withouth packagename::
by mutated (Monk) on Apr 06, 2004 at 17:16 UTC
    Thank you, I'm using export now and everything works perfectly. I had initially tried to use it, but my package had the use strict and I was using my to declaire @ISA and @EXPORT it wasn't working so I thought I was on the wrong track. I'm using our now and all is working perfectly.


    daN.
      You can still use strict while satisfying the need for @ISA and @EXPORT to be package globals in one of a couple ways. Here are some contrived examples:

      # Example 1... The best pre-Perl v5.6.0 way. package foobar; use strict; use warnings; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw(foo bar); # Example 2... The best Perl v5.6.0 + way. package foobar; use strict; use warnings; our @ISA = qw(Exporter); our @EXPORT = qw(foo bar); # Example 3... The 'base' way. package foobar; use strict; use warnings; use base qw(Exporter); # But you still have to either 'use vars' or 'our' for the # export list @EXPORT. our @EXPORT = qw(foo bar);


      Dave

      You wouldn't have maded that mistake if you had created your module stub using h2xs ...

      [tomdlux@localhost /home/tomdlux]$ h2xs -X My::MultiLevel::ModulePath Defaulting to backwards compatibility with perl 5.8.0 If you intend this module to be compatible with earlier perl versions, + please specify a minimum perl version with the -b option. Writing My/MultiLevel/ModulePath/ModulePath.pm Writing My/MultiLevel/ModulePath/Makefile.PL Writing My/MultiLevel/ModulePath/README Writing My/MultiLevel/ModulePath/t/1.t Writing My/MultiLevel/ModulePath/Changes Writing My/MultiLevel/ModulePath/MANIFEST

      --
      TTTATCGGTCGTTATATAGATGTTTGCA