Home : General : Perl Programming :

General: Perl Programming: Re: [PaulW] import vs @EXPORT_OK: Edit Log

Here is the list of edits for this post
Re: [PaulW] import vs @EXPORT_OK
Ok I got desperate and decided to look at how Links SQL does it and so I'm trying this now:

Code:
sub import {
# ------------------------------------------------------------------
#
my $pkg = shift;
my $callpkg = caller;
my @symbols = @_;

# Import requested vars.
foreach my $sym (@symbols) {
no strict 'refs';
CASE: {
($sym eq '$IN') and *{$callpkg . '::IN'} = \$IN, next;
($sym eq '$CFG') and *{$callpkg . '::CFG'} = \$CFG, next;
($sym eq '$DB') and *{$callpkg . '::DB'} = \$DB, next;
($sym eq '$TPL') and *{$callpkg . '::TPL'} = \$TPL, next;
($sym eq '$HTM') and *{$callpkg . '::HTM'} = \$HTM, next;
($sym eq '$LIB') and *{$callpkg . '::LIB'} = \$LIB, next;

die "Invalid symbol: $sym imported by $callpkg";
}
}

# Create variables requested.
my %symbols = map { $_ => 1 } @symbols;
init_vars(\%symbols);
}

Now, in the main script, wt.cgi this works great and I can use $CFG $DB etc....but it won't work in my modules.

Putting this:

use LoadMe qw/$CFG/;

print $CFG->{USER};

...in the main script works....putting the same in a module says "explicit package bla bla"

Any ideas please :(

Last edited by:

PaulW: Nov 23, 2001, 10:06 AM

Edit Log: