Peterson, Darren - Contractor.Westar wrote:
> I'd like to remove duplicate values from an array to leave it with
> only unique values. For instance, if an array contains
> (1,2,3,1,4,2,5) as values, I'd like to clean out the extra 1 and 2 to
> leave the values as (1,2,3,4,5). Does perl have an array command to
> do that, or must the process be purely manual?
The canonical response is to use a temporary hash along the lines of:
@arr = do { my %seen; grep !$seen{$_}++, @arr };
There's a Tie::Array::Unique module on CPAN which gives you a lot more
flexibility in handling this kind of thing.
See also the FAQ article
perldoc -q 'How can I remove duplicate elements from a list or array?'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>