Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Suppose I had the following output from cvs log and what I want to do is strip off the last comment of each output. I tried using the negative lookahead, but I was unsuccessful. So what I want to strip off are the lines that begin with "------" to the line that ends with "====", but I only want to strip the last comment for each file. thanks, --eric
RCS file: /cvsroot/work/bar.txt Working file: work/bar.txt head: 1.1 branch: locks: strict access list: keyword substitution: kv total revisions: 2; selected revisions: 2 description: ---------------------------- revision 1.1 date: 2001/08/23 00:19:47; author: joe; state: dead; branches: 1.1.2; file bar.txt was initially added on branch main. ---------------------------- revision 1.1.2.1 date: 2001/08/23 00:19:47; author: joe; state: Exp; lines: +3 -0 adding some stuff to the document ====================================================================== +======= RCS file: /cvsroot/work/foo.txt Working file: work/foo.txt head: 1.1 branch: locks: strict access list: keyword substitution: kv total revisions: 2; selected revisions: 2 description: ---------------------------- revision 1.1 date: 2001/08/23 00:19:47; author: joe; state: dead; branches: 1.1.2; file foo.txt was initially added on branch main. ---------------------------- revision 1.1.2.1 date: 2001/08/23 00:19:47; author: joe; state: Exp; lines: +3 -0 adding new text to my first file ====================================================================== +=======

Replies are listed 'Best First'.
Re: cvs log parsing (REGEX)
by meonkeys (Chaplain) on Sep 06, 2001 at 04:43 UTC
    I'd recommend parsing the ,v file yourself (CVS makes one of these for every file in the repository). Otherwise, you're making assumptions about record seperators that aren't necessarily true. For instance, any text can appear in the output of a CVS log command, including those that could possibly be used for record seperators. The ,v files have true record separators.
Re: cvs log parsing (REGEX)
by blakem (Monsignor) on Sep 06, 2001 at 04:32 UTC
    I couldn't tell if the "stripped off" portion was the good part that you were interested in, or the bad part that you wanted to trash. Here is a quick script that assumes the stripped off part was to be tossed away.....
    #!/usr/bin/perl -wT use strict; my $commentsep = '-' x 28; my $recordsep = '=' x 77; { local $/ = $recordsep; # slurp everything up to the record sepera +tor for my $record (<DATA>) { my @arr = split(/$commentsep/,$record); # split on the comment sep +arator if (@arr > 1) { # if we have at least one +comment $arr[-1] = ''; # remove the last one $arr[-2] .= "$recordsep"; } print join($commentsep,@arr); } } __DATA__ RCS file: /cvsroot/work/bar.txt Working file: work/bar.txt head: 1.1 branch: locks: strict access list: keyword substitution: kv total revisions: 2; selected revisions: 2 description: ---------------------------- revision 1.1 date: 2001/08/23 00:19:47; author: joe; state: dead; branches: 1.1.2; file bar.txt was initially added on branch main. ---------------------------- revision 1.1.2.1 date: 2001/08/23 00:19:47; author: joe; state: Exp; lines: +3 -0 adding some stuff to the document ====================================================================== +======= RCS file: /cvsroot/work/foo.txt Working file: work/foo.txt head: 1.1 branch: locks: strict access list: keyword substitution: kv total revisions: 2; selected revisions: 2 description: ---------------------------- revision 1.1 date: 2001/08/23 00:19:47; author: joe; state: dead; branches: 1.1.2; file foo.txt was initially added on branch main. ---------------------------- revision 1.1.2.1 date: 2001/08/23 00:19:47; author: joe; state: Exp; lines: +3 -0 adding new text to my first file ====================================================================== +=======

    -Blake

Re: cvs log parsing (REGEX)
by lestrrat (Deacon) on Sep 06, 2001 at 04:31 UTC

    Can't you just strip everything from "description:" to "RCS file" or end of the string?

    ## note: untested, and probably really inefficient ## but you get the idea. $output =~ s/description:.*?(?=RCS file|\Z)/\n/msg;
Re: cvs log parsing (REGEX)
by George_Sherston (Vicar) on Sep 06, 2001 at 10:47 UTC
    How much memory do you have? If you have enough, then this wd be a simple answer:
    my @data_array = split('=' x 77, $data_string); my @result_array; for (@data_array) { @result_array = split('-' x 28, $_); if ($you_want_to_KEEP_the_last_comment) { print $result_array[$#result_array]; } else { pop @result_array; print join('-' x 28,@result_array); } }
    si in incipio non vinces, cape malleum maior
    ("if at first you don't succeed, use a bigger hammer")

    § George Sherston