in reply to Extract Duplicates by one liner

Extract, as in "gimme the duplicates"? It's a FAQ, but here's an answer anyway:
my @dups = do {my %h; grep $h{$_}++, @array};

Replies are listed 'Best First'.
Re^2: Extract Duplicates by one liner
by hardburn (Abbot) on Mar 04, 2005 at 15:26 UTC

    That doesn't seem to work:

    $ perl -le 'my @array = qw( foo bar bar baz); my @dups = do {my %h; gr +ep $h{$_}++, @array}; print join( ", ", @dup );' $

    Update: Nevermind. That'll teach me to use strict.

    Prints nothing.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.