Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Link methods to hash values

by lyklev (Pilgrim)
on Oct 01, 2006 at 19:06 UTC ( #575807=note: print w/replies, xml ) Need Help??


in reply to Link methods to hash values

You should probably ask yourself whether this is really the way you want to go. First of all, you don't feel like defining one hundred methods for one hundred hash keys. But say you find a way, you still have at least one hundred different calls, so are you ok with that? It will be very difficult to let your program grow.

Why don't you try to understand 'objects' (that is, blessed references) first, define a getter, a setter and making the key as one of the arguments. The getter and setter methods can validate the input for you.

If you really insist and if you are prepared to follow the narrow, steep, winding path you could use a method called AUTOLOAD; this method will be called in case the requested method can not be found. It allows you to examine the method that was called, so you can extract the desired key from the method. In fact, the O'Reilly book "Perl Objects, References and Modules", chapter 11 (or its successor "Intermediate Perl") describes how to do just what you want.

Replies are listed 'Best First'.
Re^2: Link methods to hash values
by Herkum (Parson) on Oct 01, 2006 at 22:34 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://575807]
help
Chatterbox?
LanX will call his fifth son "Edsger"
[karlgoethebier]: erix: ...there is still the other Donald
LanX unfair Knuth has a "pipe organ"
LanX has only an ordinary nose.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2017-12-12 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (335 votes). Check out past polls.

    Notices?