Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hello monks,

I have a module called "DIVISION.pm" which has two subroutines namely "divideInteger","printer"
And also i have a global variable namely "$value" in that module

the "divideInteger" subroutine in DIVISION.pm do the calculation and store the result in the "$value" variable.
The "printer" subroutine in DIVISION.pm prints the value "$value"

the following is my code,
use DIVISION; divideInteger(56,2); printer(); __END__ will this program print the value "23"; how the allocation for the module is done ?
can you explain me how the allocation for the module is done when we include the module in the program using use DIVISION;

Replies are listed 'Best First'.
Re: subroutine calls
by davido (Cardinal) on Apr 14, 2006 at 07:30 UTC

    The use command, the way you're using it, is the same as the following snippet:

    BEGIN { require DIVISION; import DIVISION qw/divideInteger printer/; } # Assuming the subs you're describing are actually imported into # package main's namespace.

    The mechanism at work is described in much better detail in perlmod, and use.


    Dave

      hi monks,
      package DIVISION; require Exporter; @local::ISA=(Exporter); @local::EXPORT=qw(divideInteger printer);
      Can you explain in detail what does the 3rd and 4th lines mean??
      Is that making two subroutines local to the package DIVISION.

        No, that's making two arrays (@ISA and @EXPORT) in the package local. You want

        package DIVISION; require Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( divideInteger printer );

        And to re-read the docs for Exporter.

        Not at all. It makes the package DIVISION an "Exporter", and it actually exports the two subs to the caller's namespace. If you don't use Exporter, you'll have to call the subs this way :
        my $number = DIVISION::divideInterger(5,42); DIVISION::printer();