First some points that will help you forever:
#!/usr/bin/perl use warnings; # can be simplified to just #!/usr/bin/perl -w # this will work even on Windows!! Windows Perl doesn't look # at the path, but it does look at the -w trailing thing. You will see this often at the start of a Perl program: #!/usr/bin/perl -w use strict;
Warnings has a runtime impact, but normally I would "use warnings" except in the case of very well debugged, high performance code and even then I would think twice about leaving warnings out!

I would add "use strict;". Strict is a compile time thing and has no impact upon code execution time. It enforces scoping rules as one of the main things. Your code doesn't compile under "strict".

The syntax: &sub_name is deprecated. You can just say "sub_name;" or "sub_name();, or sub_name($parm1, $parm2)".

sub menu_system($bs_index){....} is wrong in Perl.
Perl does have a prototype mechanism but is not strongly typed (to say the least!). In any event the Perl prototype mechanism could say something like: I require at least 3 and possibly 4 scalar values. Calling the sub with 2 or 5 values would be rejected during compile. Most Perl programs don't even worry about this and for your first code, I would wouldn't either and I'm not even going to demonstrate this syntax because I don't think you need it.

A Perl sub gets a "stack" of stuff. The Perl subroutine does what it wants with this "stack of stuff".

Update: I forgot to add this sub param stuff:

sub A { my $parm1 = shift; #effect: literally shift off the stack passed } sub B { my ($p1,$p2,$p3) = @_; #effect: make copy from stack passed }
I am a bit confused with your code, but I will present the Perl way of a standard command loop that uses text as a command:
while ( (print "Enter Command: "), (my $line = <STDIN>) !~ /^\s*q(uit)?\s*$/i ) { next if $line =~ /^\s*$/; #skip new lines next if $line =~/^\s*skip/i; #skip is a no op command insert if $line =~/^\s*insert/i; #do insert command delete if $line =~/^\s*delete/i; #do delete command #...etc.. } sub insert() {...} sub delete() {...}
There are of course many variations on the above. But it is short and to the point.

I recommend not trying to be overly complex. I have written fancy hash driven dispatch tables, but I don't think that is what you need.


In reply to Re: Subroutine references inside of a hash with arguments. by Marshall
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.