Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

(tye)Re: How to build a real multi-level dispatch table

by tye (Cardinal)
on Jan 08, 2002 at 02:00 UTC ( #136971=note: print w/ replies, xml ) Need Help??

in reply to Re: How to build a real multi-level dispatch table
in thread Why I Hate Nested If-Else blocks

That is what closures are for:

my %actions= ( MainPage => sub { MainPage( $Persis, $UserName ) }, Course => sub { EditCourse( $Persist, def(\$g{CourseID},sub{GetNewCourse()}), $g{Return} ) }, EditCourse => 'Course', 'Create Course' => sub { EditCourse( $Persist, GetNewCourse($UserName), $g{Return} ) }, EditEvent => sub { EditEvent( $Persist, $g{CourseID}, $g{Return} ) }, 'New Venue' => sub { EditVenue( $Persist, GetNewVenue($Persist,$UserName), $g{Return} ) }, Venue => sub { EditVenue( $Persist, $g{'VenueID'}, $g{'Return'} ) }, EditVenue => 'Venue', 'Delete Course' => \&DeleteCoursePage, 'Keep Course' => sub { if ($g{'Return'} eq 'CourseView') { CourseView($Persist, $UserName); } else { MainPage($Persist, $UserName); } }, # ... ); # ... my $action= $actions{ $g{Action} }; if( ! $action ) { MainPage( $Persist, $UserName, $UserCookie ); } else { $action= $actions{$action} if ! ref($action); $action->(); }
where you add more subroutines as needed to keep the hash declaration from being too complex.

        - tye (but my friends call me "Tye")

Comment on (tye)Re: How to build a real multi-level dispatch table
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://136971]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2015-02-27 22:48 GMT
Find Nodes?
    Voting Booth?

    On my keyboard, Caps lock is:

    Results (457 votes), past polls