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

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

Thread Previous | Thread Next
From:
John Peacock
Date:
July 31, 2016 15:48
Subject:
Re: [perl #128786] making $^V a version object broke functionality
Message ID:
7993030e-c8b9-f258-d868-dc21062b9d66@havurah-software.org
On 07/31/2016 10:04 AM, l.mai@web.de wrote:
> # New Ticket Created by  l.mai@web.de
> # Please include the string:  [perl #128786]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/Ticket/Display.html?id=128786 >
>
>
>
> This is a bug report for perl from l.mai@web.de,
> generated with the help of perlbug 1.40 running under perl 5.24.0.
>
>
> -----------------------------------------------------------------
> [Please describe your issue here]
>
> perldoc perl5100delta:
>
> | $^V is now a "version" object instead of a v-string
> |   $^V can still be used with the %vd format in printf, but any
> |   character-level operations will now access the string representation of
> |   the "version" object and not the ordinals of a v-string. Expressions like
> |   "substr($^V, 0, 2)" or "split //, $^V" no longer work and must be
> |   rewritten.
>
> OK, they must be rewritten. But how?
>
> Consider e.g.
>
>     printf "use feature ':%vd';\n", substr($^V, 0, 2);

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];

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.

If you'd like to open a feature request for version.pm 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.

Thanks

John

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