in reply to Separate duplicate and unique records

Collect the stats first, then if the count is 1, its unique, otherwise its a duplicate:
... while (<IN>) { $seen{$_}++; } foreach my $id (sort keys %seen) { if ( $seen{$id} == 1 ) { print UNQ "$id\n"; } else { print DUP "$id\n"; } } ...

Replies are listed 'Best First'.
Re: Re: Separate duplicate and unique records
by Abstraction (Friar) on Aug 07, 2003 at 20:38 UTC
    A dup needs printed to the file each time it appears.

    (Untested)

    ... while (<IN>) { $seen{$_}++; } foreach my $id (sort keys %seen) { if ( $seen{$id} == 1 ) { print UNQ "$id\n"; } else { print DUP "$id\n" foreach 1..$seen{$id}; } } ...
Re: Re: Separate duplicate and unique records
by halley (Prior) on Aug 07, 2003 at 20:43 UTC
    The sort keys %seen offered here would render the outputs sorted, not in the order they were originaly found. This may or may not be suitable.

    You can either keep a separate array of all unique items in the order discovered, or you can look at Tie::IxHash for an already-bundled solution.

    --
    [ e d @ h a l l e y . c c ]