Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: How Critical is Critic?

by Bod (Parson)
on May 29, 2023 at 22:20 UTC ( [id://11152484]=note: print w/replies, xml ) Need Help??


in reply to Re^3: How Critical is Critic?
in thread How Critical is Critic?

I would conclude our code review meeting by reaching for a towel to wipe the egg off my face. :)

...and I would ensure you save face by asking for your expert opinion on what you would do if you were me when this situation recurs...

Which of these do you suggest I use and why? I am not entirely sure of the practical differences.

our $VERSION = '0.1_1'; $VERSION = eval $VERSION;
or perhaps
our $VERSION = '0.1_1'; $VERSION = eval { $VERSION };
or maybe
use version; our $VERSION = version->parse('0.1_1');
or something else entirely...

I believe that eval { ... }; is compiled just once whereas eval ...; is compiled each time the module is instantiated. This may make a difference if the module is created for each use like MIME::Lite. However, this module should only be created once and subsequent method calls achieve everything it does.

I don't see the point in fetching in the version module (even though it is core) to do something that can be done in two lines of simple code. Perhaps it does something more that I'm not aware of?

Replies are listed 'Best First'.
Re^5: How Critical is Critic?
by Haarg (Priest) on May 30, 2023 at 03:03 UTC
    The reasonable version of this idiom is:
    our $VERSION = '0.1_1'; $VERSION =~ tr/_//d;
Re^5: How Critical is Critic?
by hv (Prior) on May 29, 2023 at 23:26 UTC
    % perl -wle ' our $VERSION = "0.1_1"; $VERSION = eval $VERSION; if ($VERSION > 0.1 && $VERSION < 0.2) { print "ok"; } else { print "not ok"; } ' ok % perl -wle ' our $VERSION = "0.1_1"; $VERSION = eval { $VERSION }; if ($VERSION > 0.1 && $VERSION < 0.2) { print "ok"; } else { print "not ok"; } ' Argument "0.1_1" isn't numeric in numeric gt (>) at -e line 4. not ok %

    eval STRING and eval BLOCK do different things. In this case the BLOCK form is effectively a no-op, so the string is numified using standard coercion during the comparison, and yields the value 0.1 (plus a warning). The string form means "take this string and interpret it as a program" - and Perl code lets us put underscores in numbers, even though the standard coercion rejects them, so it evaluates as the value 0.11.

    I don't know about the version->parse variant, but I imagine that PAUSE would not find a version number to parse, so the module would not be indexed correctly.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found