Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

by tye (Sage)
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")

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://136971]
[james28909]: i can extract a certain tree manually by regexing the html file for a starting anchor, then i send the position of the match to a sub and then seek to that position in the file and keep up with div tags (for now)
[james28909]: how can i manage multiple tags? other than div?
[james28909]: i count the div and /div and when count == 0 it means i have got that nested tree

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2017-04-25 03:58 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (448 votes). Check out past polls.