在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
看来的代码,测试通过 #!/usr/bin/perl sub func1 { print "func1 is running\n"; } sub func_test { my $func_ref = shift; # ref will return 'CODE' if it's function reference if ( ( ref($func_ref) eq "CODE" ) && defined( &{$func_ref} ) ) { &{$func_ref}; print $@ if $@; } else { print "Not real function was called! \n"; } } ## testing from here my $func_ref = \&func1; my $anoy_ref = sub { print "anonymous function is running\n" }; my $var = "abcd"; my $var_ref = \$var; func_test($func_ref); func_test($anoy_ref); func_test($var); func_test($var_ref) my $variableName = 10 #定义私有变量 function test { my $a = shift; } #函数参数其实是个数组 #shift删除并返回数组第一个元素 修改之前的代码: #! /usr/bin/perl #传参测试 sub hello { my $a = shift; print $a; } &hello("hello,world\n"); #返回值测试 sub max { my $a = shift; my $b = shift; if ($a > $b) { return $a; } else { return $b; } } $n = &max(10,23); print $n; print "\n";
|
请发表评论