Ok, you want some context... (following are snippets... actual code is very long)
use constant RTN_EXIT => 0; use constant RTN_CONTINUE => 1; use constant RTN_ERROR => 2; # ActionSubs hash ommitted for brevity.. (it contains over 40 entries +) %ActionSubsM = ( 'emailagenda' => \&emailagenda, 'defaultagenda' => \&defaultagenda, 'createnewdefaultagenda' => \&createnewdefaultagenda, 'deleteagenda' => \&deleteagenda ); # Parsing code ommitted for brevity... (loads %FORM hash) if (%FORM) { #Are there any entries in the %FORM hash from the par +ser? $FormCmd=$FORM{'action'} # Determine if the relevant commands are listed in any of the dispatch + hash tables, and if so, run the referenced subroutine with the appro +priate arguments.... $CmdFound=-1; + $RtnVal=RTN_EXIT; + #By default, all command +s exit if (exists $ActionSubs{ $FormCmd } ) { + #Found in %ActionSubs hash? $CmdFound = 1; #Run the subroutine from %ActionSubs corresponding to string argum +ent in $FORM{'action'}... $ActionSubs{ $FormCmd }->(); #HOW TO RETURN A VALUE HERE??? DOES + NOT WORK! unless ( $RtnVal == RTN_CONTINUE ) { exit; } } elsif ( ( exists $ActionSubsM{ $FormCmd } ) && $FORM{'meetingid'}) { + #Found in %ActionSubsM hash? $CmdFound = 1; #Run the subroutine from %ActionSubsE corresponding to string argu +ment in $FORM{'action'} with argument supplied by $FORM{'meetingid'}. +.. $ActionSubsM{ $FormCmd }->( $FORM{'meetingid'} ); #HOW TO RETURN A + VALUE HERE??? DOES NOT WORK! unless ( $RtnVal == RTN_CONTINUE ) { exit; } } # etc. 2 other hash dispatch tables looked at. }
Sorry if you need more, but it is just too long to post the whole thing here. Hope this is enough.
Basically, I cannot seem to get the following kind of thing to work:
$RtnVal=$DispatchedSub($MyKey)->();The subroutine referenced by hypothetical "$DispatchedSub($MyKey)" is intended to return a constant telling the main routine whether it should exit or continue on and serve up the webpage. Trying to get the exits out of the subroutines.
I tried the following, but it did not work either:
$RtnVal=( $DispatchedSub($MyKey)->() );I do not have to do the explicit setting of $RtnVal (since it is set in the subs)... I just prefer explicit code for code clarity.
In reply to Re^2: Return value from code reference stored in dispatch table
by SteveTheTechie
in thread Return value from code reference stored in dispatch table
by SteveTheTechie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |