Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to find and remove duplicate elements from an array?

by simmisam (Novice)
on Jan 15, 2014 at 19:45 UTC ( [id://1070723]=note: print w/replies, xml ) Need Help??


in reply to How to find and remove duplicate elements from an array?

A solution that uses Tie::IxHash, a tie-able which preserves the keys of a hash in the order in which they were added:
use Tie::IxHash; sub removeDuplicates { tie my %tempHash, 'Tie::IxHash'; $tempHash{$_}++ for @_; keys %tempHash; } # Remove repeated elements from an array my @array1 = qw( 4 3 7 4 3 8 9 12 23 43 23 12 ); my @uniqArray = removeDuplicates( @array1 ); print "@uniqArray";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1070723]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-23 09:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found