in reply to assigning arrays as values to keys of hash

I guess while we are beating this thing to death...
I find this pretty easy to read... List::Util is great module.

#!/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
    @{$hash{$_}} = uniq @{$hash{$_}} for keys %hash;

    I think
        @$_ = uniq @$_ for values %hash;
    is more concise and even easier to read :)


    Give a man a fish:  <%-{-{-{-<