#! /usr/local/bin/perl -w # # threshold - Pick lines whose prefix numbers pass the threshold. # use strict; use Getopt::Long; my $threshold = 0; my $opt_duplicate; main(); sub main { parse_options(); while (<>) { if (/^\s*(\d+)\s+(.*)/) { my $score = $1; my $rest = $2; if ($score >= $threshold) { if (defined $opt_duplicate) { for (my $i = 0; $i < $score; $i++) { print $rest, "\n"; } } else { print; } } } } } sub parse_options { my $tstr = ""; # threshold string Getopt::Long::Configure('bundling'); # GetOptions handle "-123" in backward order. GetOptions('d|duplicate' => \$opt_duplicate, 't|threshold=i' => \$threshold, '0|0' => sub { my ($opt) = @_; $tstr .= $opt; }, '1|1' => sub { my ($opt) = @_; $tstr .= $opt; }, '2|2' => sub { my ($opt) = @_; $tstr .= $opt; }, '3|3' => sub { my ($opt) = @_; $tstr .= $opt; }, '4|4' => sub { my ($opt) = @_; $tstr .= $opt; }, '5|5' => sub { my ($opt) = @_; $tstr .= $opt; }, '6|6' => sub { my ($opt) = @_; $tstr .= $opt; }, '7|7' => sub { my ($opt) = @_; $tstr .= $opt; }, '8|8' => sub { my ($opt) = @_; $tstr .= $opt; }, '9|9' => sub { my ($opt) = @_; $tstr .= $opt; }, ); $threshold = $tstr if $tstr ne ""; }