Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

eval $VERSION in modules?

by ennuikiller (Acolyte)
on Jan 04, 2010 at 21:12 UTC ( #815646=perlquestion: print w/replies, xml ) Need Help??

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

What is the purpose of:

our $VERSION = '0.08';
$VERSION = eval $VERSION;

Replies are listed 'Best First'.
Re: eval $VERSION in modules?
by Khen1950fx (Canon) on Jan 05, 2010 at 06:40 UTC
    Here's an excellent article by xdg that will help clear things up: version-numbers-should-be-boring.

    Update: I just noticed where your confusion might be originating

    our $VERSION = '0.08'; $Version = eval $VERSION;
    "0.08' doesn't fit in here. Using xdg's example:
    our $VERSION = '0.001_001'; $VERSION = eval $VERSION;
    It's the "decimal alpha version" or the numbers used by "developer releases". Those releases must use decimal alpha to keep from reporting the wrong module version number.
Re: eval $VERSION in modules?
by JadeNB (Chaplain) on Jan 04, 2010 at 21:23 UTC

    A bit of Googling turns up 'eval' $ExtUtils::MakeMaker::VERSION to make it numeric. It doesn't seem like that'd be necessary in your case, but it's apparently idiomatic usage in some cases:

    The added statement is the 'standard' method of handling development version numbers.

    UPDATE: JavaFan points out that the possible is not the same as the good. I was not recommending this trick (in fact, I'd never seen it before), just trying to explain what it might mean.

      But that's only useful if you don't control the assignment of $VERSION itself (like $ExtUtils::MakeMaker::VERSION). If you want to put a numerical value in a variable, then:
      our $var = 'string looking like a number'; $var = eval $var;
      is not the way to earn brownie points. Suggest that during a job interview with me, and I won't recommend to my boss to hire you. You want a number inside your variable? Omit the quotes, don't use eval:
      our $VERSION = 0.08;

        I was ignorantly cut-and-pasting; thanks for clarifying why the idiom is useful for ExtUtils::MakeMaker but not for most uses.

        I considered mentioning the quotes, but didn't, because I thought that Perl determined the ‘purpose’ of a scalar when it was used, not when it was created. As you point out, I was wrong:

        $ perl -MDevel::Peek -e 'Dump "0.08"; Dump 0.08' SV = PV(0x80306c) at 0x800cc0 REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x205700 "0.08"\0 CUR = 4 LEN = 8 SV = NV(0x812e00) at 0x800c6c REFCNT = 1 FLAGS = (NOK,READONLY,pNOK) NV = 0.08

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://815646]
Approved by Perlbotics
Front-paged by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2023-02-04 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?