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.
In reply to Re: Extracting Unique Characters from a Array
by rsriram
in thread Extracting Unique Characters from a Array
by ps
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |