Thanks for all the great responses! I have not had a chance to read through all of them but I did get the script working the way I wanted, albeit, maybe not the most efficient way.

I have changed the hash into an array as I dropped the menu names early on but never changed the hash. I am going solely off of Indexes now (thanks for pointing that out ikegami!).

I then used an  eval() on the menu subroutine names in the array elements rather than the $menu_hash{$bs_index}->();

I have attached a simple example of the script without the neat menu navigation back\forward\restart\ options that are in the real deal. This is just an example so don't expect a whole lot of error checking and polish.

#!/usr/bin/perl use warnings; print "********************************************\n"; print "* test app\n"; print "* Version 0.2 - \"The mule\"\n"; print "********************************************\n"; print "\n"; #Define global args my @menu_list = ( "&default", "&get_ifc_name({'ifc_default' => 'test.ifc0'})", "&get_ip_address({'ipaddr_default' => '10.20.1.1'})", "&headr_section", ); &menu_system; sub menu_system(){ #Define our menu system here with the appropriate subs and thier argum +ents $bs_index = shift; #first run check to setup the first menu if(!$bs_index){ #start things off at the first menu $bs_index = "1"; } print "\n*** DBG MENU SYSTEM: Index from args: $bs_index ***"; #check to see if the menu index is defined, otherwise display an error +. if (defined $menu_list[$bs_index]){ #menu is valid, run the sub print "\n*** DBG MENU SYSTEM: running ID: $bs_index ***\n\n" +; eval($menu_list[$bs_index]); } else { print "*** Unknown Menu Called***\n"; } } sub get_ip_address() { my($arg) = shift; print "IP for the Interface [ \"$arg->{'ipaddr_default' +}\" ]\n"; $ip_addr = <STDIN>; chomp($ip_addr); &menu_system("3"); } sub get_ifc_name() { my($arg) = shift; print "Enter an Interface Name [ \"$arg->{'ifc_default' +}\" ]\n"; $device_name = <STDIN>; chomp($device_name); &menu_system("2"); } sub headr_section{ print "*******************************************\n"; print "* Section 2 Header\n"; print "* To skip a step, type \"skip\"\n"; print "* To go back a step, type \"back\"\n"; print "* To restart this step, type \"restart\"\n"; print "********************************************\n\n"; }
This may not be the best way to do this but it is working for me without any side effects so far. Any pointers are welcome! I don't mind the criticism.

In reply to Re^2: Subroutine references inside of a hash with arguments. by shift9999
in thread Subroutine references inside of a hash with arguments. by shift9999

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.