Parse revisions from log file

I need to verify file revisions in a log file that I'm writing out with a perl script.
The log file, has the following lines in it, among other things:

<===cut from log===>
File: Helpus/All/build.xml
before Release20060411_01:
   Sticky Tag:            Q20060330 (revision: 1.1)

after Release20060411_01
   Sticky Tag:            Release20060404_01 (revision: 1.2)
<===cut from log===>

I'd like to add a revision audit function to my current perl script.
I need to look for
1)revisions going backwards ("before" "revision: 1.1" and "after" "revision:1.0")...
...as well as
2)revision hopping (before 1.1, after 1.3).

I need to audit each file in the log file.
Each file has an entry similar to the build.xml <=cut=> from above.
If the file is indicated in the log as violating #1 or #2, I like to write the file name listed in the log after "File:" to an alert text file.

Thanks for any help!
I haven't had time to hack anything together and I like learn from the experts anyway.


jwcorbettAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
I'm not quite sure what it is you want to do.
Given the above cut from log as input, what would you want the output of the sctipt to be?
jwcorbettAuthor Commented:
The output would depend on the revisions listed for the given filename.
So, in the cut, the filename (and path) is Helpus/All/build.xml
I would want "Helpus/All/build.xml" listed in a new text file if the revisions for it either go backward, or hop (skip) a revision.
ozoCommented:
So, given the above cut from log, you would not have any output?
Would (before 1.9, after 2.0) be a skip?
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

jwcorbettAuthor Commented:
Correct, the cut from above would not have output...
No, before 1.9, after 2.0 would not be a skip, it would be valid.

So the two examples where I'd need an alert text file written to would be:
Skip (revision 1.2 is skipped):
<===cut from log===>
File: Helpus/All/build.xml
before Release20060411_01:
   Sticky Tag:          Q20060330 (revision: 1.1)

after Release20060411_01
   Sticky Tag:          Release20060404_01 (revision: 1.3)
<===cut from log===>

and backwards:
<===cut from log===>
File: Helpus/All/build.xml
before Release20060411_01:
   Sticky Tag:          Q20060330 (revision: 1.3)

after Release20060411_01
   Sticky Tag:          Release20060404_01 (revision: 1.2)
<===cut from log===>

Hope this helps and thanks for yours!
ozoCommented:
I'm still not quite sure how skip is defined.
would 1.85 to 2.01 be a skip?
would 1.9 to 1.10 be a skip?  Would it be backwards?
how about 1.2.1 to 1.3.1?
jwcorbettAuthor Commented:
Basically, I think it comes down to evaluating the digits between the dots.

would 1.85 to 2.01 be a skip?
Yes, this is a skip.  
This scenario (1.X to 2.X), is somwhat hard to handle...for this one the "OK" scenario would be 1.85 to 1.86.

would 1.9 to 1.10 be a skip?  Would it be backwards?
This would be OK, not a skip or backwards.

how about 1.2.1 to 1.3.1
Yes, this would be a skip, 1.2.1 going to 1.2.2 would be OK.





ozoCommented:
So what is allowed to preceed 2.0?
1.9 is ok, 1.85 is not, what about 1.99 or 1.9.9?
jwcorbettAuthor Commented:
For the purposes of this script, going to 2.0 from any 1.X would be a skip (1.9 to 2.0 is not OK, 1.9 to 1.10 would be OK).

In practice, if we go to 2.0 from 1.X, it's a new release and would be handled accordingly (baseline would start at 2.X).



ozoCommented:
#maybe you want something like this.  I'm not sure about the skip condition
#!/usr/bin/perl
$/="File: ";
while( <> ){
    next unless /^before.*revision:\s*([\d.]+).*after.*revision:\s*([\d.]+)/ms;
    $before=eval"v$1";    $after=eval"v$2";
    print /(\S.*)/," backwards \n" if $after lt $before;
    print /(\S.*)/," skip\n" if ord(substr$before,-1)+1 < ord(substr$after,-1)\
;
}
jwcorbettAuthor Commented:
Initial test show that this will get me going...let me get it implemented into the script before I close out the question.

Thanks Ozo! Once again, it's Ozo nice to have you around!
ozoCommented:
Or maybe this is better
#!/usr/bin/perl
$/="File: ";
while( <> ){
    next unless /^before\s.*?revision:\s*([\d.]+).*?^after\s.*?revision:\s*([\d.]+)/ms;
    $after=eval"v$2";
    $next=eval"v$1";
    substr($next,-1)=chr(ord(substr$next,-1)+1);
    print /(\S.*)/," backwards\n" if $after lt $next;
    print /(\S.*)/," skip\n" if $next lt $after;
}
jwcorbettAuthor Commented:
Not really better...it lists files whose revision did not change as going backwards...
ozoCommented:
#!/usr/bin/perl
$/="File: ";
while( <> ){
    next unless /^before\s.*?revision:\s*([\d.]+).*?^after\s.*?revision:\s*([\d.]+)/ms;
    $after=eval"v$2";
    $before=eval"v$1";
    $next=$before;
    substr($next,-1)=chr(ord(substr$next,-1)+1);
    print /(\S.*)/," backwards\n" if $after lt $before;
    print /(\S.*)/," skip\n" if $next lt $after;
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jwcorbettAuthor Commented:
That's better...what do you see as the primary differences between your 1st script and the last one?
jwcorbettAuthor Commented:
Ozo,

How can I get "print /(\S.*)/" into a variable?
If the revision does skip or goes backwards, I'd like to take some action on the filename, but I can't seem to get the filename into a variable...
ozoCommented:
($variable) = /(\S.*)/;
jwcorbettAuthor Commented:
That's what I thought too, but when I do that, my variable is equal to 1...

I changed the syntax a bit from the original, this what I'm using:
        if ( "$next" lt "$after" ) {
            print /(\S.*)/," skipped revisions\n";
            $FILEDREV = /(\S.*)/;
            print "The file is $FILEDREV\n";
        }

When I use a log file that has a skipped revision, the output is:
MMS2/All/versions.properties skipped revisions
The file is 1

ozoCommented:
($FILEDREV) = /(\S.*)/;
ozoCommented:
the ( ) puts it in list context
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.