in reply to How do I get the position of the same value in array or list.
First create a HoA, keys of the hash are the values from the array @data, and the arrays contain the indices in @data where each data can be found.foreach (@data) { push(@$pos{$_},$i++); } foreach (keys %pos) { if ($#{$pos{$_}) { print join(" and ",map("\$data[$_]",@$pos{$_}))," have the same +value: $_\n"; } }
Then just print those keys where the size of the list of indices is more than 1.
Due to the nature of the way we fill the HoA, there won't be any empty lists (Otherwise I'd have to be carefull of the $#==-1 case.)
|
|---|