> <Script> > #Perl Script to Compare two backup logs and then identify > # substantial differences in changed tables. > use strict; > use warnings; > > #Open the newer backup log. > open FILE, "C:/tmp/max_grow/max1.log" or die "Cann't open : $!"; > while(<FILE>){ > chomp; > > #Input to be divided in two: > #Sample of file is - > # APPDOCTYPE 43 > # APPLAUNCH 16 > # APTRANS 1245 > # ARCHIVE 0 > # ASICUST 24 > # ASILINK 5 > # ASSETATTRIBUTE 736 > # ASSETCLASS 1667 > # ASSIGNMENT 60648 > # ATTENDANCE 103193 > > #Divide the input into two groups > s/(.*\D)+(.*\d)/$2 $1/;
If you are only interested in $1 and $2 why use a s///, just a m/// or /// would do. > > #Pass the two groups to variables > my $value1 = $2; > my $tblnam1 = $1; Assigning contents from $1, $2 ... etc. must be done inside a condition that checks for the success of the regex. These variables are not cleared, if the regex fails they will still contain the old values. > > #Remove all unnecessary spaces. > for ($tblnam1) { > s/^\s+//; > s/\s*$//;} > for ($value1) { > s/^\s+//; > s/\s*$//;} You could have avoided the chomp, regexes etc. by using split (perldoc -f split). In particular the default behaviour of split. my ($tblnam1,$value1) = split; $tblnam1 and $value1 will now contain the values you want in them. > > #Open the older log > open FILE2, "C:/tmp/max_grow/max4.log" or die "Cann't open : $!"; > while(<FILE2>){ > chomp; > s/(.*\D)+(.*\d)/$2 $1/; > > my $value2 = $2; > my $tblnam2 = $1; > > > for ($tblnam2) { > s/^\s+//; > s/\s*$//;} > for ($value2) { > s/^\s+//; > s/\s*$//;} The same holds here too, default behaviour of split > > # Compare the two logfiles here. > if($tblnam1 eq $tblnam2) { > my $diff = $value2 - $value1; > if($diff > 1000){ > print "$tblnam1 :The difference is $diff\n"; > } > } > > } > } > </End Script> It seems like for every line in log1 you are opening log2 and doing the comparison. With m lines in log1 and n lines in log2 you are performing m*n operations. A better option would be to open log1 and form a hash. open (LOG1, $your_first_log) or die "...."; while (<LOG1>) { my ($tablnm1, $value1) = split; $comp_log{$tablnm1} = $value1; } close <LOG1> or warn "....."; Now loop through log2 and check if a key with tblnam2 exists in the hash and if it does subtract the values for the result. open (LOG2, $your_second_log) or die "...."; while (<LOG2>) { my ($tablnm2, $value2) = split; if (defined $comp_log{$tablnm2}) { # Doing your difference check here } } close (LOG2) or warn "....."; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]