in reply to Why is @flds not imported?
You gotta be super careful when you place a module in a script or in the same file as another module. It's very easy to execute code in the wrong order. And this is what happened here.
Let's look at the following simplified version of your code:
{ package Fields; our (@flds, @EXPORT); @EXPORT=qw(@flds); use Exporter 'import'; } package main; use Fields; my $nfld = scalar @flds;
In broad strokes, the following is the compilation and execution process:
Note the relative order of the statements in bold. At the time of import, @EXPORT was empty.
Fix:
BEGIN { package Fields; use strict; use warnings; use mem; our (@flds, @EXPORT); @EXPORT=qw(@flds); use Exporter 'import'; $INC{"Fields.pm"} = 1; } { # <-- Not necessary, but enforces cleaner code. use strict; use warnings; use Fields; my $nfld = scalar @flds; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why is @flds not imported?
by LanX (Saint) on Sep 25, 2017 at 01:33 UTC | |
by perl-diddler (Chaplain) on Sep 25, 2017 at 02:46 UTC | |
by LanX (Saint) on Sep 25, 2017 at 09:01 UTC | |
by perl-diddler (Chaplain) on Sep 26, 2017 at 23:32 UTC | |
|
Re^2: Why is @flds not imported?
by perl-diddler (Chaplain) on Sep 25, 2017 at 00:08 UTC | |
by LanX (Saint) on Sep 25, 2017 at 01:36 UTC | |
by perl-diddler (Chaplain) on Sep 25, 2017 at 03:05 UTC |