Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

cvs revision extraction regex

by chicks (Scribe)
on Apr 21, 2002 at 17:18 UTC ( [id://160901]=CUFP: print w/replies, xml ) Need Help??

This will extract the cvs version number for the current file into a scalar.
$VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /: (\d+)\.(\d+)/);

Replies are listed 'Best First'.
Re: cvs revision extraction regex
by Chmrr (Vicar) on Apr 21, 2002 at 18:43 UTC

    I use the following (first seen, if I remember correctly, from one of merlyn's bits of code):

    $VERSION = (qw$Revision: 1.12 $ )[-1];

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

      I used the same until I ran into a problem comparing versions between a single and double-digit minor version.

      my $new = 1.41; my $old = 1.5; print $new > $old ? $new : $old;

      I figured 'nothing a fancier sort can't fix, right?' until I realized it also broke use My::Module N.NN;, so thesedays I use a style I saw in one of Gisle Aas' modules...

      $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /: (\d+)\.(\d+)/);

      That way single digits get 0-padded (ie, 1.05 vs 1.5, although 1.1.1.1 gets turned into 1.01) and all is right with the world again. :)

          --k.


        It's so cool to have gotten such a response to this little snippet. :-)

        I certainly like Gisle's version (thanks kanji!). I might do something more like %03d instead of %02d since some of my files get revised that often, but otherwise that's the best thing I've seen.

        I changed the snippet itself to reflect this...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://160901]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 10:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found