In Perl, how can a subroutine get a coderef that points to itself?

后端 未结 5 735
情歌与酒
情歌与酒 2020-12-24 07:02

For learning purposes, I am toying around with the idea of building event-driven programs in Perl and noticed that it might be nice if a subroutine that was registered as an

5条回答
  •  醉梦人生
    2020-12-24 07:48

    If you don't change $cb's value again, you can use that. If not, define a scalar to hold that and don't change it ever again. For example:

    my $cb = do {
      my $sub;
      $sub = sub { contents using $sub here }
    }
    

提交回复
热议问题