- 论坛徽章:
- 0
|
- use File::Find;
- my $callback;
- {
- my $count = 0;
- $callback = sub { print ++$count, ": $File::Find::name\n" };
- }
- find($callback, '.');
复制代码 Here, we declare a variable to hold the callback. We cannot declare this variable within the naked block (the block following that is not part of a larger Perl syntax construct), or Perl will recycle it at the end of that block. Next, the lexical $count variable is initialized to 0. We then declare an anonymous subroutine and place its reference into $callback. This subroutine is a closure because it refers to the lexical $count variable.
Intermediate.Perl,第7.4节 , closure没看懂啊!求各位指教。 |
|