in reply to unique elements in an array
It's all there for you at cpan: Array::Unique.
use Array::Unique; tie @a, 'Array::Unique'; @a = qw(a b c a d e f); push @a, qw(x b z); print "@a\n"; # a b c d e f x z
The POD states: "This package lets you create an array which will allow only one occurrence of any value. In other words no matter how many times you put in 42 it will keep only the first occurrence and the rest will be dropped."
There is also japhy's Tie::Array::Unique. It behaves a little differently, but is also more configurable, allowing for case-insensitive matching, etc.
Dave
|
|---|