in reply to Separate duplicate and unique records

I got interrupted or I'd have put this up earlier. This is much like thelonius's solution. I post it only because it shows the queue idea much more clearly.

In this code the line:

($cur, $next) = ( $next, scalar( <IN>));
may be generalized to slide any size window over a stream:
@queue[0 .. 4 ] = ( @queue[ 1 .. 3], scalar( <IN> ));
Also I like to setup such a queue going into a loop than clean up a queue when exiting a loop. It seems clearer to me but I can only call that a personal preference.

This code seems to work.

#!/usr/bin/perl -T use strict; use warnings; my ( $input, $unique, $dupe) = qw( input unique dupes ); my $is_dupe; open( IN, $input ) or die "Can not open $input"; open( UNIQUE, ">", $unique ) or die "Can not open $unique"; open( DUPES, ">", $dupe ) or die "Can not open $dupe"; my $cur = <IN>; exit if not defined $cur; my $next = <IN>; no warnings "uninitialized"; while ( 1) { if ( $cur == $next) { print DUPES $cur; $is_dupe = 1; } else { if ( $is_dupe) { print DUPES $cur; } else { print UNIQUE $cur; } $is_dupe = 0; } ($cur, $next) = ( $next, scalar( <IN>)); last if not defined $cur; }