作者gugod (啊)
看板Perl
标题Re: [问题] block 的意思
时间Sat Mar 10 00:28:16 2018
※ 引述《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 当中。
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 122.147.252.210
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Perl/M.1520612900.A.5D7.html