How to avoid pushing duplicate values into a Perl array -
i need add unique elements in array inputs contain several duplicate values.
how avoid pushing duplicate values perl array?
you need use hash this:
my %hash; $hash{$key} = $value; # can use 1 $value ...
this automatically overwrite duplicate keys.
when need print it, use:
foreach $key (keys %hash) { # $key }
if need sort keys, use
foreach $key (sort keys %hash) ...
Comments
Post a Comment