Skip to content

Commit

Permalink
add script to creat pt with only certain scores
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuhoang committed Apr 20, 2014
1 parent 568685c commit 76a4609
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions scripts/other/delete-scores.perl
@@ -0,0 +1,61 @@
#!/usr/bin/perl

use strict;
use Getopt::Long "GetOptions";

binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");

sub trim($);
sub DeleteScore;

my $keepScoresStr;
GetOptions(
"keep-scores=s" => \$keepScoresStr
) or exit(1);

my @keepScores = split(/,/, $keepScoresStr);

#MAIN LOOP
while (my $line = <STDIN>) {
chomp($line);
#print STDERR "line=$line\n";

my @toks = split(/\|/, $line);
my @scores = split(/ /, $toks[6]);

$toks[6] = DeleteScore($toks[6], \@keepScores);

# output
print $toks[0];
for (my $i = 1; $i < scalar(@toks); ++$i) {
print "|" .$toks[$i];
}
print "\n";
}

######################
# Perl trim function to remove whitespace from the start and end of the string
sub trim($) {
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}

sub DeleteScore
{
my $string = $_[0];
my @keepScores = @{$_[1]};

$string = trim($string);
my @toks = split(/ /, $string);

$string = "";
for (my $i = 0; $i < scalar(@keepScores); ++$i) {
$string .= $toks[ $keepScores[$i] ] ." ";
}
$string = " " .$string;

return $string;
}

0 comments on commit 76a4609

Please sign in to comment.