How can I add only unique values to an anonymous array used as a hash value?

Easiest way would be to put an anonymous hash at $hash{$key} You only care about the keys of that anonymous hash.

Easiest way would be to put an anonymous hash at $hash{$key}. You only care about the keys of that anonymous hash. #!

/usr/bin/perl use strict; use warnings; my %hash; while ( my $line = ) { chomp $line; my ($key, $val) = split /\s*=\s*/, $line; $hash{$key}{$val} = undef; } for my $key ( keys %hash ) { printf "%s : %s \n", $key, join(' ', keys %{ $hash{$key} }); } __DATA__ key = 1 key = 2 other = 1 other = 2 key = 2 key = 3 In the output, key = 2 appears only once: C:\Temp> h other : 1 2 key : 1 3 2 .

You can just do: $hash{$key} = $keyvalue unless exists $hash{$key}; This will add the key,value pair ($key,$keyvalue) only if the key is not already present in the hash.

You don't push values into a hash, since a hash needs key/value pairs and push only adds a value. In your expression you're treating $hash{$key} as an array reference to which you want to add a value. You just have to normally assign the value to the hash.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions