in reply to How do I get the position of the same value in array or list.
A hash will help,
%hsh becomes a Hash-of-Arrays with push, then we just look for arrays bigger than 1. I restricted that to 2 for the example.my %hsh; push @{$hsh{$data[$_]}}, $_ for 0..$#data; for (keys %hsh) { printf '$data[%d] and $data[%d] have the same value!!', @{$hsh{$_}} if @{$hsh{$_}} == 2; }
Update: tinita++, corrected.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How do I get the position of the same value in array or list.
by tinita (Parson) on Apr 07, 2004 at 08:08 UTC |