小编use*_*165的帖子

在Perl中,如何在数组中找到最后定义的元素?

使用Perl,我希望找到数组中定义的最后一个元素.

到目前为止,我有以下内容:

#generating array
$array[100] = (undef);
$array[$columns[1]-1] = $columns [2];

#finding the last element that is defined
for ($i=100; $i>=0; $i--) {
    if (($array[$i] != undef) && (!defined($lastdef)) ){
        $lastdef=$i;
    }
}
Run Code Online (Sandbox Code Playgroud)

我不确定为什么这不起作用.有什么建议要改进,使用Perl?

arrays perl for-loop defined conditional-statements

2
推荐指数
1
解决办法
418
查看次数

标签 统计

arrays ×1

conditional-statements ×1

defined ×1

for-loop ×1

perl ×1