perl 裡邊的 函式指標

bulletming發表於2019-02-24
mysql@greatdba:~/install/dbtools/temp> more testfunc.pl
#!/usr/bin/perl
sub install_precheck {
        my $str=shift;
        print "it is in install_precheck: $str\n";
}
sub install_mysql {
        my $str=shift;
        print "it is in install mysql: $str\n";
}
sub mysql_priv_init {
        my $str=shift;
        print "it is in mysql_priv_init: $str\n";
}
my %proc_table = (

        'install_precheck' => \&install_precheck,
        'install_mysql' => \&install_mysql,
        'mysql_priv_init' => \&mysql_priv_init

);
print $proc_table{'install_precheck'} . "\n";
&{$proc_table{'install_precheck'}}('abc');
$proc_table{'install_mysql'}('mysql install');
$proc_table{'stall_mysql'};

mysql@greatdba:~/install/dbtools/temp> ./testfunc.pl
CODE(0x8167738)
it is in install_precheck: abc
it is in install mysql: mysql install

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/82392/viewspace-536380/,如需轉載,請註明出處,否則將追究法律責任。

相關文章