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

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -