Skip to content

Instantly share code, notes, and snippets.

@tagomoris
Created December 22, 2011 05:40
Show Gist options
  • Save tagomoris/1509101 to your computer and use it in GitHub Desktop.
Save tagomoris/1509101 to your computer and use it in GitHub Desktop.
check tags/data length
#!/usr/bin/env perl
use 5.14.0;
my $odata = '============================================================================================================================================================================================================================================================================================================';
my $data_length = length($odata);
my $seq = {first => [], second => [], third => [], forth => []};
my $lines = 0;
my $bytes = 0;
my $broken = 0;
while(my $line = <STDIN>){
$lines += 1;
$bytes += length($line);
chomp $line;
my ($tag, $data) = split(/\t/, $line, 2);
unless ($tag and $tag =~ /^(first|second|third|forth)(\d{8})$/ and $data and length($data) == $data_length) {
$broken += 1;
next;
}
my $tagname = $1;
my $num = $2;
my $pair = $seq->{$tagname}->[-1] || [-2, -2];
if ($pair->[1] == $num - 1) {
$pair->[1] = $num;
}
else {
push $seq->{$tagname}, [$num, $num];
}
}
foreach my $tagname (keys %$seq) {
foreach my $pair (@{$seq->{$tagname}}) {
print $tagname, "\t", $pair->[0], "\t", $pair->[1], "\n";
}
}
print "lines\t", $lines, "\n";
print "bytes\t", $bytes, "\n";
print "broken\t", $broken, "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment