#!/usr/bin/perl
#
# eg8: indexlist example, long version..
#

use strict;
use warnings;

my @array = ( 17, 5, 3, 17, 2, 5, 7, 6, 6, 10, 3 );

my %indexlist; # build array element -> list of positions in original array

# - initialize all ’inner’ array refs to [], maybe several times each
foreach my $value (@array)
{
	$indexlist{$value} = [];
}
# - now push each index onto @{$indexlist{value}}
foreach my $index (0..$#array)
{
	my $value = $array[$index];
	my $aref = $indexlist{$value};
	push @$aref, $index;
}

# build @uniq, all unique elements of @array
my @uniq = grep { @{$indexlist{$_}} == 1 } @array;
my $str = join(',',@uniq); print qq($str\n);
