#!/usr/bin/perl $COLLROOT='abc'; $SARRAY{"-c"} = "$COLLROOT/coll_us"; print "\n"; print " Input SBY Output NPO Output\n"; print "================================================================= =============== ==========\n"; if ( $ARGV[0] eq "" ) { output_a_line("123456","123456"); print "\n"; } else { # output_a_line($ARGV[0], "who knows?"); output_a_line("@ARGV", "who knows?"); } print "\n"; exit; sub output_a_line { local($test_value)=@_[0]; local($correct_answer)=@_[1]; $SBY_answer=SBY_filter_UP($test_value); $NPO_answer=filter_UP($test_value); $SBY_answer_length=length($SBY_answer); $NPO_answer_length=length($NPO_answer); unless ($SBY_answer eq $correct_answer) { $SBY_answer="\033[7m$SBY_answer\033[0m";} unless ($NPO_answer eq $correct_answer) { $NPO_answer="\033[7m$NPO_answer\033[0m";} $right_pad1=" " x (16-$SBY_answer_length); $right_pad2=" " x (58-$NPO_answer_length); printf "%-66s %s%s %s%s\n", $test_value, $SBY_answer, $right_pad1, $NPO_answer, $right_pad2; return; } # (EVS) Normalized patentnumbers, numbers only # Name: UP # Input: Lots of different formats, could be divide by comma or space # Output: normalized UP-number separated by comma sub SBY_filter_UP { my($in_var) = @_; # If there's any kind of "funny" character in this search string, don't modify it at all. return $in_var if ($in_var !~ /^[a-zA-Z\d\/_\?\*,\ ]*$/); my $return_var = ""; my @pns = split(/[\ |,]/, $in_var); foreach my $pns (@pns) { if ($pns ne "") { my $tpn = $pns; if ($pns =~ /\*/) { } elsif ($pns =~ /([A-Z]{0,2})([0-9\?]{4})([\/])([\d\?]{1,11})([A-Z_\?]*[0-9]*)/ix) { $tpn = $2 . "0" x (7 - length($4)) . $4; } elsif ($pns =~ /([A-Z\?]{0,2})([A-Z\?]{0,2})0*([\d\?]{1,11})([A-Z_\?]*[0-9]*)/ix) { $tpn = $3; if (($2 eq ""?$1:$2) =~ /(RE|PP|D)/ix) { $tpn = uc $1 . "0" x (8 - length($1) - length($tpn)) . $tpn; } } else { $return_var .= ($return_var ne "" ? "," : "").$tpn; } } } return $return_var; } # Leading zeros with patentnumber # Name: UP # Input: Less than 8 digits and no wildcard # Output: fill up with leading zeros till 8 with UP sub filter_UP { my ($in_var_string) = @_; my ($output,$term); # If there's any kind of "funny" character in this search string, don't modify it at all. # That is, we only filter if input is alphanumeric or a Verity operator ?*, or a comma or space. return $output if ($in_var_string !~ /^[a-zA-Z\d\\?\*,\ ]*$/); # Split our input (the search argument) into separate, comma-delimited terms, # and iterate across all search terms, rebuilding our filtered output. foreach (split /,/, $in_var_string) { # For each term, after stripping off leading zeros, we handle 2 cases only. # 1) One Letter followed by all numeric. We pad numeric portion with zeros to 7 digits. # For example, D123 or D000123 => D0000123 # 2) Two Letters followed by all numeric. We pad numeric portion with zeros to 6 digits. # For example, RE123 or RE00123 => RE000123 my $term = $_; if ( $term =~ /^ *(.*) *$/ ) { # Strip off leading and trailing blanks, if any. $term=$1; } if ( $term =~ /^0+(.*)$/ ) { # Strip off leading zeros if any. $term=$1; } if ( $term =~ /^([a-zA-Z])0*(\d{1,5})$/ ) { $term = $1 . "0" x (6-length($2)) . $2; # Input is D00123, e.g. } elsif ( $term =~ /^([a-zA-Z]{2})0*(\d{1,4})$/ ) { $term = $1 . "0" x (5-length($2)) . $2; # Input is RR0123, e.g. } # Rebuild the search string with the commas we're parsing on, in our foreach/split loop. if ($output eq "") { # First term? I.E. First time through? $output = $term; # If so, it doesn't get a comma } else { # Else separate this term from earlier ones with a $output = $output . "," . $term; # comma. } } # End of foreach split ... return $output; }