in reply to Advice on transforming a sub into a re-entrant recursive-able method.

What seems a little strange is the no-arguments prototype () with all your functions (hint: just get rid of it), and the missing sub keyword for get_ints and get_macs. Also, you'd need a semicolon at the end of the $func_map = {...} declaration. Then, add strictures and fix the remaining problems that Perl complains about...

Replies are listed 'Best First'.
Re^2: Advice on transforming a sub into a re-entrant recursive-able method.
by hechz (Novice) on Jul 21, 2008 at 17:46 UTC
    So the basic tack is right? (like I wrote, the rewrite is more pseudo-perl than anything else).

      I haven't really looked at the semantic aspects of your rewrite yet, because I'm not exactly sure which advice from Higher Order Perl you're trying to follow, in particular which coderefs you want to pass to where...

      As it is, it's not clear to me how the three functions are related. Is snmp_get the toplevel function? If so, how is it supposed to call the other routines (via coderefs you pass in as args?), etc.  Could you elaborate a bit on how you want the new version to operate, i.e. what you want to call with which args, and what it should return (a few lines of sample code showing how you're planning to use it would help).

        The advice I am attempting to follow is from page 48 in HOP... "There is an important lesson to learn here: make functions re-entrant by default, because sometimes the usefulness of being able to call a function recursively will be a surprise"...

        The behavior I am looking for is to pass in the name of the thing I am looking for, and to generate a hash of the MACs keyed off of the interface names. I am assuming that I need to pass in sub-routines that gather the OIDs from the lookup table, and perhaps call a generic sub that performs the $snmp_sess->get_request.