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

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

Thread Previous | Thread Next
Lukas Mai
July 31, 2016 19:46
Re: [perl #128786] making $^V a version object broke functionality
Message ID:
Am 31.07.2016 um 17:48 schrieb John Peacock:
> On 07/31/2016 10:04 AM, wrote:
>> # New Ticket Created by
>> # Please include the string:  [perl #128786]
>> # in the subject line of all future correspondence about this issue.
>> # <URL: >
> Perl objects are typically just hashes of stuff, blessed into a class, e.g.
>  $ perl -w -MData::Dumper -E 'say Dumper($^V);'
>    $VAR1 = bless( {
>                  'original' => 'v5.20.2',
>                  'version' => [
>                                 5,
>                                 20,
>                                 2
>                               ],
>                  'qv' => 1
>                }, 'version' );
> So your code could be rewritten as:
>    printf "use feature ':%d.$d;\n", @{$^V->{version}}[0,1];

That's not part of the public API. I'd have to rely on implementation 
details that might change at any time.

Can this code be written at all using just the public API and without 
reparsing the pretty-printed version number? (E.g. it's easy enough to 
do 'my @v = split /\./, sprintf "%vd", $^V;' but that's cheating. And a 
bit awful.)

> v-strings are intrinsically a binary format, so you MUST treat it
> specially when trying to print or compare.  Version objects can be
> treated as a normal scalar and printed/compared using non-special methods.

1. v-strings are normal scalars: they're strings.
2. No special treatment is required for comparing v-strings. v-string 
comparison is normal string comparison.
3. Special treatment is required for comparing version objects. version 
object comparison is not normal string comparison, and inadvertently 
stringifying a version object and then comparing it leads to wrong results.
4. Pretty-printing a version number is rare in my code. Most of the time 
I only want to compare versions, extract components, and construct new 
versions (e.g. for automatically incrementing a version number, etc).

> If you'd like to open a feature request for to include
> methods to extract the epoch/major/minor/release from a version objects,
> I'd be happy to add one.  This is the first time in nearly 10 years that
> anyone has requested such a thing, but it is easy enough to add.

I'm not directly concerned with I've never had a use for it.

My main concern is being able to introspect the version number of the 
currently running perl. If that has to go through, OK.

In that case a method to return the numeric components would be nice, as 
well as a method to get the v-string representation:

     my @parts = $^V->parts;    # (5, 24, 0)
     my $str   = $^V->vstring;  # "\x05\x18\x00"

Would that be good addition to the API?

Lukas Mai <>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About