pearllearner315 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks, I have a file formatted like this:

bird beak
bird beak
bird claw
bird wings
bird feathers
snake fangs
snake scales
snake fangs
snake tail

I want to loop through this file and get the bird and snake as keys, and the word next to them as the values in an array. I only want unique elements tho for each array so for example, bird will be the key in the hash, and its corresponding value will be an array that contains (beak, claw, wings, feathers). I have the current code that works but it doesn't get rid of the duplicates:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $file = 'file.txt'; open( FILE, '<', $file ) or die $!; my %hash; while ( <FILE> ) { chomp; my $lines = $_; my $key = (split(/" "/, $lines))[0]; my $value = (split(/" "/, $lines))[1]; push @{ $hash{$key} }, $value; } print Dumper(\%hash);
How would I get rid of the duplicates in the arrays?