Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Simplify constant value determination

by Tomte (Priest)
on Aug 25, 2006 at 16:21 UTC ( #569613=perlquestion: print w/replies, xml ) Need Help??
Tomte has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
to allow for determination exactly which version of a program runs (and produces errors), I have the following statement to fetch the subversion revision-number in my code

use constant REVISION => eval { ( $_ = '$Id: mcdt.pl 2081 2006-08-25 16:16:27Z tomte $' ) =~ s/\$Id: mcdt.pl (\d+) .*/$1/; $_; };
While I think its reasonable and not too ugly, I wonder if theres a more concise/elegant way of retrieving the revision-number as a constant.

Edit: elimininated /g modifier

regards,
tomte


An intellectual is someone whose mind watches itself.
-- Albert Camus

Replies are listed 'Best First'.
Re: Simplify constant value determination
by ysth (Canon) on Aug 25, 2006 at 16:37 UTC
    Since you seem to just want the first group of digits:
    use constant REVISION => ('$Id: mcdt.pl 2081 2006-08-25 16:16:27Z tomt +e $' =~ /(\d+)/g)[0];
    should do it. No need for eval or substitution here.

    Update: grr, I don't use g-less m// in list context often enough to remember what it returns.

    use constant REVISION => '$Id: mcdt.pl 2081 2006-08-25 16:16:27Z tomte + $' =~ /(\d+)/;

      the last one is what i was looking for - thanks and ++ysth - the wood for the trees etc. :)

      regards,
      tomte


      An intellectual is someone whose mind watches itself.
      -- Albert Camus

Re: Simplify constant value determination
by friedo (Prior) on Aug 25, 2006 at 16:36 UTC
    How about:

    use constant REVISION => q$Id: mcdt.pl 2081 2006-08-25 16:16:27Z tomte $ =~ /pl (\d+)/;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://569613]
Approved by Thelonius
help
Chatterbox?
[Discipulus]: Oh I got a (small but better than nothing) salary increase!! beer for all!
[cavac]: Not sure if it's only my connection, but pause.cpan.org seems rather slow to respond today.
[cavac]: Could some of you just log in for a second and check, for example, the tail daemon logfile?

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2017-02-22 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (325 votes). Check out past polls.