in reply to Adding Unique Elements to Array

thekestrel,
Here is how I would do it:
#!/usr/bin/perl use strict; use warnings; my @uniq; my $add = uniq_array( \@uniq ); $add->(3,1,4,1,5,9); $add->(2,7,2,7,2,7); print "$_\n" for @uniq; sub uniq_array { my ($aref, %uniq) = shift(); return sub { push @$aref, grep { ! $uniq{$_}++ } @_ }; }
Let me know if you have any questions.

Cheers - L~R

Update: Over 2 months after posting this, Roy Johnson asked why I used map instead of grep inside the return sub. The answer is that I was modifying a piece of existing code that does much more. For the sake of clarity, I have replaced the funny looking map.