bob
the easiest way to do this is to use all elements of your dirty as keys
to a hash. there are shorter forms to this solution, but i'll leave it
verbose for clarity;
hope this helps
-r
################################################## #############
# see
#
http://perlmonks.com/index.pl?node=609
# for reference
################################################## #############
use strict;
my @dirty = ( 1, 2, 3, 2, 3, 4, 9, 8, 7, 6, 5, 4, 3, 2, 1);
#
# the hash we will use to track unique elements in @dirty
#
my %occurred;
foreach my $dirtyElement ( @dirty )
{
$occurred{$dirtyElement} = 1;
}
#
# we can now retrieve the unique elements from %occurred
#
my @unique = keys %occurred;
print @unique;
################################################## #############
"Bob" <> wrote in news:1109737474.473572.207520
@g14g2000cwa.googlegroups.com:
> Sorry i cut and pasted only half of the code!
>
> @SORTED = ();
> @CLEANED = ();
> $X = 0;
> $R = 0;
> while ($R < 4)
> {
> while ($X <= 100)
> {
> $X++;
> # print "I am in X\n";
> # # i really do not want to write to the array if
> # # it already exists in the array.
> # # if array already has X then do not right to the
> # # array.
> push @CHECKED, $X;
> @SORTED = sort {$a <=> $b} @CHECKED;
> }
> # print "*********I am in R\n";
> $R++;
> $X = 0;
> next;
> }
>
> print "Array = @SORTED\n";
>
> $Element2 = 0;
>
> for ($Element1 = 0; $Element1 < @SORTED; $Element++)
> {
> $Element2 = ($Element1 + 1);
> if ($SORTED[$Element1] == $SORTED[$Element2])
> {
> print "$SORTED[$Element1] == $SORTED[$Element2]\n";
> delete $SORTED[$Element2];
> $Element1--;
> next;
> }
> else
> {
> next;
> }
> }
> # # How do i remove duplicates from the array?
> # # I know this is wrong but here is my delima!
>
> print "Array = @CLEANED\n";
>