Hi all,
I'm trying to call a sub-routine based on the value of a variable.
More specifically, I'm developing a menu system, where each level of the
menu has it's own sub-routine, but for a generalized "back" function, I'm
trying to call the last menu based on a variable, something like:
$lastMenu = apiMenu;
&$lastMenu; #I want this to be the same as calling &apiMenu
Does this make any sense?
Any help is greatly appreciated!
I guess I'll try to appretiate your post one more time, being in a
diffrent frame of mind.
Like I said, don't really know *what* type of menu system your talking about,
the availability of options on each level, saved frames, and so forth..
It does not appear you want anything other than a level scalar array of hashes
that contain sub references to handlers that know and where it is and can react,
based on some interpreted *key* selected via keyboard (?) input.
The sub's probably have identical parameters, or passed a constant structure
from which more sub/level, individual data can be processed. This is not easy.
Also, you may want to save state of the data previously entered if its revisited.
Likewise, you may want to carry around a master data structure that has been sucessfully
populated from previous visits as you progress down the menu tree towards the
final *SUBMIT/SAVE* conclusion. Again not easy. But entirely possible.
Consider that its a windows menu tree, where you are calling successive dialog's,
populating a master data structure along the way. A cancel out of a single dialog
invalidates *only* a portion of the master that you are populating. Consecutive
<backspace> could load previously entered data (incase the user just wanted to
change one item), but would probably invalidate the forward data if a backward
change deems it so.
.............
One way is:
# in key form, @menutext_hasharrays contains "Text" to display and
# corresponding index to the selected @m(x) that is current.
@menutext_hasharrays = (
# main
{'N' => [1, "'N'ext"], 'Q' => [3, "'Q'uit"],
'A' => [4, "'A'item"], 'B' => [5, "'B'item"], 'C' => [6, "'C'item"] },
# level 1
{'N' => [1, "'N'ext"], 'B' => [2, "'B'ack"], 'Q' => [3, "'Q'uit"],
'A' => [4, "'A'item"], 'B' => [5, "'B'item"], 'C' => [6, "'C'item"] },
# level 2
{'N' => [1, "'N'ext"], 'B' => [2, "'B'ack"], 'Q' => [3, "'Q'uit"],
'A' => [4, "'A'item"], 'B' => [5, "'B'item"] },
# level 3
{'N' => [1, "'N'ext"], 'B' => [2, "'B'ack"], 'Q' => [3, "'Q'uit"],
'A' => [4, "'A'item"], 'B' => [5, "'B'item"], 'C' => [6, "'C'item"] },
);
# @m(x) handler array's:
# index 0 always equals index to @menutext_hasharrays (for menu display options and
# holds indexes to handlers at the current level, this so a particular item need not
# be in order when displaying the option),
# index 1 always equals ref to "next" @m(x) array
# index 2 always equals ref to "last" @m(x) array (if back)
# index 3 always equals ref to "quit", can be custom specific to a menu ..
# index 4 - ... are the specific handlers for this menu level
# indexes > 2 are handlers
@mm = (0, \@m1, undef, \&quit);
@m1 = (1, \@m2, \@mm, \$quit, \&h11, \&h12, \&h13);
@m2 = (2, \@m3, \@m1, \$quit, \&h21, \&h22);
@m3 = (3, undef, \@m2, \$quit, \&h31, \&h32, \&h33);
..........
The rest is left as an exercise.
You have to read between the lines. All values in the anom array's in
@menutext_hasharrays are arbitrary except for the indexes into the @m(x) handler array's
The concept is driven from the knowledge of initially starting with a known @m(x) array
by default.
This is one of several ways to implement this in Perl, depending on your perspective.
There is always a *static* degree to this process. It *always* has some degree of
indirection, ie: building tables of references to others.
This is for character driven menu's. There's another way which is a derritive of this
that involves further indirection might drive you insane to even think about it.
Or that I don't care to explain...
The graphic method and the issues discussed above all can work depending on what wants
to be accomplished.
Hey, I'm not getting paid for this shit....
robic0