Wor*_*ter 0 arrays perl groovy initialization ternary-operator
我现在的问题是基于我在CSV文档中遇到的问题,但它也更普遍.
我希望在Java/Groovy/Gosu中使用类似null的问号来确定数组索引是否已初始化.
我有类似的东西:
for ( my i = 0; i < @engVals or i < @frenchVals; i++ ) {
$csv->print($file, [ $engVals[i] ?: "", , $frenchVals[i] ?: "" ] );
# Where Elvis ops ensure that the array element at i is initialized, and if not stores blank in the CSV
}
Run Code Online (Sandbox Code Playgroud)
defined $engVals[i]
Run Code Online (Sandbox Code Playgroud)
见http://perldoc.perl.org/functions/defined.html
或者你可以做到
$engVals[i] // ''
Run Code Online (Sandbox Code Playgroud)
请参阅http://perldoc.perl.org/perlop.html#Logical-Defined-Or