Perl Style: Functions as Data

  • Use function pointers as function arguments or in data structures:

        # from MxScreen in TSA (see also PCB 19.12)
        %State_Table = (
            Initial  => \&show_top,
            Execute  => \&run_query,
            Format   => \&get_format,
            Login    => \&resister_login,
            Review   => \&review_selections,
            Sorting  => \&get_sorting,
            Wizard   => \&wizards_only,
        );
    
        foreach my $state (sort keys %State_Table) {
            my $function = $State_Table{$state};
            my $how      = ($action == $function)
                            ? SCREEN_DISPLAY
                            : SCREEN_HIDDEN;
            $function->($how);
        }
    

Forward to Closures
Back to Configuration Files
Up to index

Copyright © 1998, Tom Christiansen All rights reserved.

Tags

Feedback

Something wrong with this article? Help us out by opening an issue or pull request on GitHub

TPRF Gold Sponsor
TPRF Silver Sponsor
TPRF Bronze Sponsor