[tpm] Irritation problem

Chris Jones cj at enersave.ca
Mon Apr 9 17:02:56 PDT 2012


Further to my last email, I revised the code to try to weed out 
leading ../../ and ./../
There must be an elegant way to eliminate the new inner if statement 
by combining it in the first test:
if( $cfgLine =~ /([\w]+)\t([-\w\/.]+)$/)

I added this inner if statement as I couldn't think of a way to 
combine, this may be preferable as more readable:
Part of code:
if( $value =~ m!^.{1,2}/.{2}/!)  weed out leading ../../ and ./../
                 {
                         print( "Value bad: $value\n");
                         $badValue++;
                 }

START Code:
use strict;
my $tool_input = "d:/screeningtool.ca/input";

open my $fhIn, "$tool_input/config1.dat" or die "config1.dat not found\n";

my %confighash;
my $count = 0;
my $badValue = 0;
my $goodValue = 0;
while( my $cfgLine = <$fhIn> )
{
         $cfgLine =~ s/#.*//;            # ignore comments by erasing them
         next if ($cfgLine =~ /^(\s)*$/);  # skip blank lines
         chomp( $cfgLine );              # remove trailing newline characters
         #print( "Okay\n" );

         if( $cfgLine =~ /([\w]+)\t([-\w\/.]+)$/) #
         {
                 my $key = $1;
                 my $value =  $2;
                 if( $value =~ m!^.{1,2}/.{2}/!)
                 {
                         print( "Value bad: $value\n");
                         $badValue++;
                 }
                 else
                 {
                         print ("Key: $key, Value: $value\n");
                         $goodValue++;;
                 }
                 $confighash{ $key } = $value;
                 $count++;
         }

}
close $fhIn;
print( "Count: $count, Good values: $goodValue, Bad values: $badValue\n");

END Code


 >>
Christopher Jones, P.Eng.
Suite 1801, 1 Yonge Street
Toronto, ON M5E1W7
Tel. 416-203-7465
Fax. 416-946-1005
email cj at enersave.ca



More information about the toronto-pm mailing list