Created
August 12, 2010 15:33
-
-
Save ray1729/521160 to your computer and use it in GitHub Desktop.
Process common chunks of a sorted input stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings FATAL => 'all'; | |
my ( $key, @values ) = next_record(); | |
while ( defined $key ) { | |
my ( $next_key, @next_values ) = next_record(); | |
if ( defined $next_key and $next_key eq $key ) { | |
push @values, @next_values; | |
} | |
else { | |
print join( "\t", $key, @values ) . "\n"; | |
$key = $next_key; | |
@values = @next_values; | |
} | |
} | |
sub next_record { | |
defined( local $_ = <> ) or return; | |
chomp; split; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment