Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Why doesn't @EXPORT = (keys %METHODS) work?

by btrott (Parson)
on Mar 15, 2001 at 06:26 UTC ( [id://64601]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://64601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-20 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found