Why can't I call my exported routine in my Perl program?

I am new to Perl and I am facing the following problem without having a clue why the following is not working.

My Perl module contains:

package PACK2;
use Exporter;
@ISA = ('Exporter');
@EXPORT_OK=('whom');

sub why(){
    print "why\n";
}

sub whom(){
      print "whom\n";
}
1;

My Perl file contains:

#!/usr/bin/perl -w

use pack;
use pack2 ('whom');

PACK::who();
&whom();

I run this program and cannot find whom:

perl use_pack_pm.pl

who
Undefined subroutine &main::whom called at use_pack_pm.pl line 7.
+3
source share
3 answers

Perl is a case sensitive language. I do not think that the modules "pack2" and "PACK2" are the same. (But I have not really tested this.)

+8
source

Internally use pack2 ('whom');translated to something like

BEGIN {
    require pack2;
    pack2->import('whom');
}

, perl , import pack2, . pack2 import . , perl import, Exporter.

, Perl , . OO - import.

+5

.

. , Dir, package Dir::Module;, package Module ;. .

0
source

Source: https://habr.com/ru/post/1764912/


All Articles