在调试perl程序时perl -d,如何将其限制为仅进入给定的模块集或路径lib?
假设用户想要根据特定条件从数组中过滤元素.用户有两种选择.要么他可以使用一行grep语句,要么写一个for循环并根据特定条件存储元素.
例如
my @array = (1, 2, 3, 4, 5, 6, 7, 8);
选项1 : my @filtered = grep { $_/2 eq 0 } @array;
选项2:
foreach (@array)
{
if($_/2 eq 0) {
push @filtered, $_;
}
}
Run Code Online (Sandbox Code Playgroud)
如果性能是一个因素,哪种是首选的写作方式?