perl - 理解 Perl 中的语法
问题描述
我可能有一个非常简单的问题,关于理解 Perl 的语法是如何真正起作用的。
unless ($alleles{$child}) {
say (join "\t","line $.","no alleles in child") if $debug;
next LINE;
我想要实现的是,我在一个数组中没有超过 1 个孩子,所以我需要摆脱 $child 并用数组 @children 替换它,但是有些行我不知道这是否也可以工作只是将 $child 更改为数组所以当我将其更改为数组时,这真的会遍历数组的所有项目吗?
解决方案
我不能完全说出你想要什么,但我认为它是以下之一:
use List::Util qw( any );
# If $alleles{$_} is true for one or more element of @children
if ( any { $alleles{$_} } @children ) {
...
}
use List::Util qw( all );
# If $alleles{$_} is true for every element of @children
if ( all { $alleles{$_} } @children ) {
...
}
# If $alleles{$_} is true for more than one element of @children
if ( ( grep { $alleles{$_} } @children ) > 1 ) {
...
}
推荐阅读
- cakephp - Cakephp 显示应用程序状态
- javascript - django表单实时选择值字段
- php - 如何验证段落内的“文件”字段是否填写在drupal表单中?
- c# - 通过异常类型捕获没有实体数据库错误
- ruby - Ruby 解释器在 :key_down 上崩溃
- r - 多个 .txt 导入中的小数分隔符
- python-3.x - Python:在 Pandas 中按行计算
- git - 如何跟踪嵌套在未跟踪文件夹中的文件?
- string - Beckhoff - 从另一个查询的结果构建查询
- c# - 最新的 VS Mac 更新导致 Xamarin Android 中的 SetContentView(resourceid) 出现 SIGSEGV