in reply to Why doesn't @EXPORT = (keys %METHODS) work?

Several problems here. Some are just typos, I think. For example you have "%keys %METHODS"; presumably you just mean "keys %METHODS". Another is you have "*$methods" where presumably you mean "$method".

But the main problem is that you need to set up your %METHODS hash in the BEGIN block, so that it gets initialized *before* you try to use it. Ie.:

my(%METHODS); our @EXPORT; BEGIN { %METHODS = ( foo => 'bar', bo => 'baz', ); @EXPORT = keys %METHODS; foreach my $method (keys %METHODS) { no strict 'refs'; *$methods = sub { return $METHODS{ $method }; }; } }

Replies are listed 'Best First'.
Re (tilly) 2 (no begin): Why doesn't @EXPORT = (keys %METHODS) work?
by tilly (Archbishop) on Mar 17, 2001 at 18:27 UTC
    To my eyes moving more into BEGIN is solving one mistake by making another. Just lose the BEGIN block entirely and (as merlyn pointed out) don't mess up your populating the array and hash. Also avoid the $method/$methods typo that you have.

    It will work just fine. After all from the point of view of the place where you are being used from, you already ARE in a BEGIN block...

Re: Re: Why doesn't @EXPORT = (keys %METHODS) work?
by dws (Chancellor) on Mar 15, 2001 at 06:41 UTC
    Looks like the culprit, though how does this square with the claim "The dynamic methods are generated with no problem"?

    I suspect that there's more going here than meets the eye. Seeing the complete script might shed more light.