我有一个哈希,填充了以下测试数据:
my %non_root_files = ('views/SPYGLASS_HOME/bin/sample_sgdc_file_contents_1.sgdc' => 1,
'views/SPYGLASS_HOME/bin/sample_sgdc_file_contents.sgdc' => 1,
'views/SPYGLASS_HOME/bin/test_2.sgdc' => 1,
'views/SPYGLASS_HOME/bin/test_4.sgdc' => 1,
'views/SPYGLASS_HOME/bin/test_5.sgdc' => 1,
'views/SPYGLASS_HOME/bin/test_6.sgdc' => 1);
在另一个数组中,我有以下数据:
my @files = ('views/SPYGLASS_HOME/bin/sample_sgdc_file_contents.sgdc',
'views/SPYGLASS_HOME/bin/test_2.sgdc',
'views/SPYGLASS_HOME/bin/sample_sgdc_file_contents_1.sgdc',
'views/SPYGLASS_HOME/bin/test_5.sgdc',
'views/SPYGLASS_HOME/bin/test_7.sgdc',
'views/SPYGLASS_HOME/bin/sample_sgdc_file_contents_2.sgdc');
我需要做的是检查数组中的每个条目是否存在于哈希中,并从原始数组中删除,所以我这样做如下:
sub deleteDuplicate{
$originalList_ref = shift;
my $index = 0;
foreach my $element (@{$originalList_ref})
{
if(exists $non_root_files{$element})
{
splice(@{$originalList_ref}, $index, 1);
}
$index++;
}
}
但是,对于某些实际存在于散列中的条目,使用存在的查找失败。该元素存在于哈希中,但如果条件返回 false。谁能解释一下这个原因以及如何纠正它?
谢谢!