in reply to assigning arrays as values to keys of hash
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use List::Util qw(uniq); my %hash; while (<DATA>) { my ($animal, $part) = split /\s+/; push @{$hash{$animal}},$part; } @{$hash{$_}} = uniq @{$hash{$_}} for keys %hash; print Dumper \%hash; __DATA__ bird beak bird beak bird claw bird wings bird feathers snake fangs snake scales snake fangs snake tail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: assigning arrays as values to keys of hash
by AnomalousMonk (Archbishop) on Sep 18, 2018 at 23:17 UTC |