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

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.