In this recipe from the Cookbook, I see how to store a reference to a fuction: http://eda.ee.nctu.edu.tw/~zephlin/O'Reilly/books/perl2/cookbook/ch11_05.htm

What I am trying to do, however, is to create a hash whose keys point to method (function) references of an object instance. Here's what it looks like currently.
$md_config->{"[cust_num]"} = \&{$web_services->GetCustomerNumber}; $md_config->{"[description]"} = \&{$web_services->GetCustomerDescripti +on};
$web_services is the object instance. The syntax seems acceptable to perl, but when I go to get the method later to run it like this:
$this->{md_config}->{"cust_num"}->();
It comes back with the error: "Undefined subroutine &MDScriptConfig:cust29435 called at MDScriptConfig.pm line 20."

What's interesting is that 'cust29435' that you see in the error message is the result of running the function pointed to in the hash. Which means it's actually working--soft of. Perl is trying to interpret the function result as a function name rather that the actual value that I'm wanting. Anyhow, I would appreciate any help you can provide.

Thanks.

-Matt

In reply to Storing/Calling References to Instance Methods by mlong

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.