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

Dear Monks,

What am I doing wrong here?

package myPackage; use Exporter; use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = qw( %tables ); @EXPORT_OK = qw(%tables); #%EXPORT_TAGS = (); my $topDir = "E:\\tables"; #### my %tables = ( ABC => { InitDir => "$topDir\\ABC\\", CtlFile => "ABC.ctl", LogFile => "ABC.log" }, XYZ => { InitDir => "$topDir\\XYZ\\", CtlFile => "DOD_CIV_PAY.ctl", LogFile => "DOD_CIV_PAY.log" }, Other => { InitDir => "$topDir\\.", CtlFile => "", LogFile => "" } ); 1;

... and here's my test script ...

#!c:\Cygwin\bin\perl.exe -wT use strict; use lib ('.'); use myPackage '%tables'; my $idir = $tables{"ABC"}{"InitDir"}; my $ctlFile = $myPackage::tables{"ABC"}{"CtlFile"}; print "[$idir] [$ctlFile]\n";

here's what happens when I run it ...

$ ./myTest.pl Use of uninitialized value in concatenation (.) or string at ./myTest. +pl line 10 Use of uninitialized value in concatenation (.) or string at ./myTest. +pl line 10 [] []

... I just don't understand how to Export stuff I guess.
Please help!

Replies are listed 'Best First'.
Re: Exporting hash?
by Zaxo (Archbishop) on Aug 14, 2002 at 20:53 UTC

    You're trying to export a lexical variable, %tables, which has file scope at most. You could instead make it a package global with use vars ('%tables'); our %tables = or else provide an accessor sub which can be exported.

    The package global will be accessed as %MyPackage::tables, but no Exporter magic is used for that.

    After Compline,
    Zaxo

Re: Exporting hash?
by stajich (Chaplain) on Aug 14, 2002 at 20:58 UTC
    The my %tables - change to our %tables if perl 5.6.x or do
    use vars qw(%tables); %tables = ( ... );