develooper Front page | perl.perl5.porters | Postings from August 2016

Re: [perl #128786] making $^V a version object broke functionality

Thread Previous | Thread Next
From:
Lukas Mai
Date:
August 3, 2016 19:58
Subject:
Re: [perl #128786] making $^V a version object broke functionality
Message ID:
041d7cac-ed5b-6c04-cfcf-0c90674e60cb@gmail.com
Am 01.08.2016 um 08:38 schrieb Zefram:
> Lukas Mai wrote:
>> My main concern is being able to introspect the version number of the
>> currently running perl.
>
> $] has always worked for that, and still does.
>
>     @parts = map { 0+$_ } sprintf("%010.6f", "$]") =~ /([0-9]{3})/g;
>

I think that's borderline obfuscated. The biggest WTF in there is "$]": 
Why are you explicitly converting a floating-point number to a string, 
only to have it be implicitly reinterpreted as a float by %f, which then 
explicitly stringifies it again?

Also, that still counts as reparsing a pretty-printed form. If I wanted 
that, I could do it more directly with

     @parts = $^V =~ /\d+/g;

(which silently fails in 5.6 and 5.8) or

     @parts = sprintf("%vd", $^V) =~ /\d+/g;
     # or
     # @parts = split /\./, sprintf "%vd", $^V;

(for compatibility).

-- 
Lukas Mai <plokinom@gmail.com>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About