in reply to Extracting Unique Characters from a Array
Hi, Assuming that your array of numbers is:
@array= qw/10 10 48 22 34 54 23 65 22/;
The easiest way to do it is first sort the array
@sarray=sort(@array);
Now I am checking through every element in the array and storing it to a variable $last_element. The current element will be stored in $i. In the if condition, I am checking if the current element is equal to the last element and if the condition is false, I am printing the element. And here is the code:
@array= qw/10 10 48 22 34 54 23 65 22/; @sarray=sort(@array); my $last_element = ""; foreach $i (@sarray) { if ($last_element ne $i) { print "$i\n"; $last_element = $i; } }
You can have answers for these types of questions at Super search.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extracting Unique Characters from a Array
by Fletch (Bishop) on Sep 07, 2006 at 17:24 UTC | |
|
Re^2: Extracting Unique Characters from a Array
by ps (Initiate) on Sep 07, 2006 at 17:21 UTC |