I have a hash that I would like to get the values for by using subroutine names. Example,
# Hash Value $hash{'name'} = 'Herk'; $self->get_name(); # Returns 'Herk'
Can someone help me fill in the blank about how I should do this?

Update

Let me state what I am avoiding trying to do. I don't want to have to create methods for every key in my hash. If I have a 100 keys I COULD write 100 get methods and 100 set methods but that is alot of work.

What I was hoping for was for one or two methods that evaluates a 'get_' or 'set_' calls, intercepts it and does an operation with my hash based upon the method name. That way all I have to worry about is making sure all my fields are in the hash.

Sorry, I was unclear in explaining what I wanted.


In reply to Link methods to hash values by Herkum

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.