Re: [問題] block 的意思
※ 引述《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://www.ptt.cc/bbs/Perl/M.1520612900.A.5D7.html
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Perl 近期熱門文章
PTT數位生活區 即時熱門文章