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

Greetings all you wise individuals, here is my question. If anyone has any idea how to do this in a simple way it would be great.

I am searching in files for lines that can look like:

-Version: 0.3 6-May-2002/Bill Buff -VERSION: 0.1 4-Jun-2001/Rita Ray -#Version 0.112 12-Apr-2002-Moon Man -*Version: 1.345 1-Jan-2002 Kay Koon -;Version 2.06 3-Feb-2002/Kobra -; VERSION 0.45 5-May-2002 Linus T - VERSION: 7-Oct-2002/Hade Roy - VERSION: Ola Ola 5.6.2002
I am only interested in finding those lines and changing them to format where everything else is skipped from line except the number:
-0.3 -0.1 -0.112 and so on.
I have not yet succeeded in making good general expression for my search, instead I am now searching for all types of name "Version" (#,spaces,;,*,infront of it) separately. All my "generalizations" just are not working.... =Problem 1

How to look for all these types of line with maybe one search expression if $line =~ m ???

Second problem, how do I then skip all the words and dates. Now I am subtituting everything (date, names) separately

If it clicks for you tell mee ,too Thanks Hewarn

Replies are listed 'Best First'.
Re: Version history dilemma
by RMGir (Prior) on Aug 20, 2002 at 17:18 UTC
    Matching, skipping, and capturing, all in one shot:
    next unless /version[: ]+([0-9.]+)/i; print "-$1\n";
    Using the /i option on the match saves you from worrying about whether it's Version, VERSION, or version.

    I'm assuming you don't care at all what comes before VERSION, or after the number, so I'm ignoring all of that...

    If the line really starts with -, and that's required, you could use:

    next unless /^-.*?version[: ]+([0-9.]+)/i; print "-$1\n";

    --
    Mike
Re: Version history dilemma
by fruiture (Curate) on Aug 20, 2002 at 17:29 UTC
    while(<>){ # method 1 : extract first version-like looking number # if string 'version' is found somehwere /version/i and /(\d+\.\d+(?:\.\d+)?)/ and $_ = "$1\n"; # method 2 : extract first version-like number after # the string 'version' /version.+(\d+\.\d+(?:\.\d+)?)/i and $_ = "$1\n"; } continue { print }

    The basic idea is not to replace "everything else" but to grab what you need throw away the rest.

    --
    http://fruiture.de
Re: Version history dilemma
by Anonymous Monk on Aug 20, 2002 at 17:18 UTC
    print "-$1\n" if /^-[#;*]?\s*version:?\s+(\d+\.\d+|)/i;