Denham Eva wrote:
> 
> Hello listers,

Hello,

> I would like to submit a script I have written and it does work. However I
> am sure that it can be:
> a. Shorter
> b. Faster
> As you will see it is not very well written. Certainly nothing compared to
> some of the listers code I have seen here.
> I am new at perl so here goes. Some of you might recognise the sample a part
> of a Oracle export log, which it is.
> Now I am not confident enough to use the unedited log and stripping it with
> perl(maybe oneday), anyway that has already been done with tools like grep
> and cut.
> <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/;
> 
> #Pass the two groups to variables
> my $value1 = $2;
> my $tblnam1 = $1;
> 
> #Remove all unnecessary spaces.
>     for ($tblnam1) {
>         s/^\s+//;
>         s/\s*$//;}
>     for ($value1) {
>         s/^\s+//;
>         s/\s*$//;}
> 
> #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*$//;}
> 
> # Compare the two logfiles here.
>                 if($tblnam1 eq $tblnam2) {
>                    my $diff = $value2 - $value1;
>                    if($diff > 1000){
>                        print "$tblnam1 :The difference is $diff\n";
>                    }
>                 }
> 
>         }
> }



I would probably do something like this:

use strict;
use warnings;

my $log_new = 'C:/tmp/max_grow/max1.log';
my $log_old = 'C:/tmp/max_grow/max4.log';
my %data;

#Open the newer backup log.
open FILE, $log_new or die "Cannot open $log_new: $!";

while ( <FILE> ) {
    next unless my( $table, $value ) = /([A-Z]+)\s*(\d+)/;
    $data{$table} = $value;
    }
close FILE;

#Open the older log
open FILE, $log_old or die "Cannot open $log_old: $!";

while ( <FILE> ) {
    next unless my( $table, $value ) = /([A-Z]+)\s*(\d+)/;

    # Compare the two logfiles here.
    if ( exists $data{$table} ) {
        my $diff = $value - $data{$table};
        if ( $diff > 1000 ) {
            print "$table :The difference is $diff\n";
            }
        }
    }

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to