in reply to Re: Why eval $version?
in thread Why eval $version?

Wouldn't it be great if ... use Foo 0.02 already dismissed underscores from $VERSION.

Doesn't it?

$ cat Foo.pm package Foo; use strict; use warnings; our $VERSION = '1.01_01'; print "Hello!\n"; 1; $ perl -I. -we 'use Foo 1.00; 1;' Hello! $

I must have missed something but there are no warnings here (on perl 5.20.3) and there's no eval in the module. Is this a solved problem?

Replies are listed 'Best First'.
Re^3: Why eval $version?
by choroba (Cardinal) on Jul 09, 2020 at 15:59 UTC
    The problem is that $Foo::VERSION is still 1.01_01, the underscore included.
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Yes, the underscore is still there. Why is that a problem?

        Often, users will take the version from Module->VERSION or $Module::VERSION and compare it to a number. This will issue a warning:

        package Module;
        our $VERSION = "1.1_2";
        my $new = Module->VERSION > 1.1;
        

        Also, for modules that want to work properly on perls older than 5.10, leaving an underscore in the $VERSION will result in a use call throwing a warning.

        > Yes, the underscore is still there. Why is that a problem?

        because a dev version will show on CPAN as a new release?

        update

        I dunno

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Re^3: Why eval $version?
by LanX (Saint) on Jul 09, 2020 at 16:18 UTC
    This works for the same reason, why eval $VERSION works, when numifying a string Perl accepts all digits till it encounters a non-digit.

    So when comparing numerically the strings won't pose a problem.

    That behavior is inherited from a C function a can't recall something like atonumber().

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      No, it works because on perl 5.10 and newer, version comparisons done by a use are performed using version (or an equivalent core routine) that accounts for the underscores, as well as multi-part versions (e.g. v1.2.3).
        So use is compiling the module found in @INC first and checks the executed package var $VERSION then?

        Hence no a priori static parsing of the source ?

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery