Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://575807]
[marto]: /mefails
[thezip]: Duh... I found it. Idempotentcy
[thezip]: howdy marto!

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-07-18 20:41 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (395 votes). Check out past polls.