在使用Perl脚本时,如果您需要创建信号处理程序,则可能会发生这种情况,因此您可以通过在函数名称前添加\&来生成对该函数的引用,并取消引用该引用,您只需要使用&前缀为引用变量加前缀。以下是一个例子-
#!/usr/bin/perl
# Function definition
sub PrintHash {
   my (%hash) = @_;
   foreach $item (%hash) {
      print "Item : $item\n";
   }
}
%hash = ('name' => 'Tom', 'age' => 19);
# Create a reference to above function.
$cref = \&PrintHash;
# Function call using reference.
&$cref(%hash);输出结果
执行以上程序后,将产生以下结果-
Item : name Item : Tom Item : age Item : 19