让我们这很容易.我想要的是:
@array = qw/one two one/; my @duplicates = duplicate(@array); print "@duplicates"; # This should now print 'one'.
如何打印数组/哈希的重复值?
sub duplicate { my @args = @_; my %items; for my $element(@args) { $items{$element}++; } return grep {$items{$_} > 1} keys %items; }