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
How would I get rid of the duplicates in the arrays?#!/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);
|
---|
Back to
Seekers of Perl Wisdom