命名子例程中的 perl 匿名子例程

标签 perl

关于下面的代码,$one_sub 和 $two_sub 如何成为命名子“sup”中匿名子程序的代码引用?命名的 sub 不会“返回”那两个匿名 subs;是吗? (至少我没有放过这样的声明)。

sub sup {

          my $neh = sub {
                  say "this is 'neh' subroutine"
          };

          my $hen = sub {
                  say "this is 'hen' subroutine"
         };
          ($neh, $hen);
  }

  my ($one_sub, $two_sub) = ⊃

使用 Data::Dumper::Streamer 显示:

$CODE1 = sub {
           use warnings;
           use strict;
           no feature;
           use feature ':5.10';
           say q[this is 'neh' subroutine];
         };
$CODE1 = sub {
           use warnings;
           use strict;
           no feature;
           use feature ':5.10';
           say q[this is 'hen' subroutine];
         };

最佳答案

引用perlsub :

If no return is found and if the last statement is an expression, its value is returned.

($neh, $hen); 是一个表达式。在列表上下文中,它的值为 2 个匿名订阅者。

关于命名子例程中的 perl 匿名子例程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31053140/

相关文章:

perl - 从散列中选择一个随 secret 钥

perl - mojolicious morbo 服务器默认缓存吗?

perl - 安装 Perl mod 后,不断收到错误 "Can' t locate Image/Grab.pm in @INC”

Perl:IO::Uncompress::Unzip:获取 zip 文件的最后修改日期

perl - 将 perl 模块拆分为多个文件

mysql - DBD-mysql错误: CPU you selected does not support x86-64 instruction set

perl - 了解元素的顺序

linux - 使用 Perl 脚本提取 tar.gz 文件

perl - 对 PERL PDL 变量执行正则表达式

arrays - 如何在 Perl 中有效地从引用的散列和键数组中获取值数组?