Re: [问题] block 的意思

楼主: gugod (å•Š)   2018-03-10 00:28:16
※ 引述《gecer (gecer)》之铭言:
: https://perldoc.perl.org/List/Util.html
: $result = reduce { BLOCK } @list
: 常看到 perldoc 提到 "BLOCK" 请问是什么意思?
基本上就是一段以大括号包起来的程式码,大致上来说在 perl 文件中常看到的
例子有:
map BLOCK LIST # perldoc -f map
grep BLOCK LIST # perldoc -f grep
if (EXPR) BLOCK # perldoc perlsyn
把文件中的 "BLOCK" 这个字换成 "{ ... }" 或许就比较好理解
map { ... } LIST
grep { ... } LIST
if (EXPR) { ... }
List::Util 文件当中的表示法略有出入,不过大致上不失原意。
可再参考此处说明: https://perldoc.perl.org/perlsyn.html#Basic-BLOCKs
由于以大括号包住,所以其中的区域变量的有效范围就限于 BLOCK 当中。

Links booklink

Contact Us: admin [ a t ] ucptt.com