Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

how check the first release of a new operand?

by xiaoyafeng (Deacon)
on Dec 07, 2020 at 08:42 UTC ( #11124766=perlquestion: print w/replies, xml ) Need Help??

xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

by corelist, I can find the first release of the core module, but How can I get the firest release of new operand(or function)? like \K // etc.

Thanks in advance.




I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

  • Comment on how check the first release of a new operand?

Replies are listed 'Best First'.
Re: how check the first release of a new operand?
by Corion (Pope) on Dec 07, 2020 at 08:50 UTC

    Syntax::Construct allows you to declare the operators you use in your code. Its documentation tells you what Perl release the feature comes from.

    See the introduced and removed subroutines there to programmatically query for features, once you know their names.

      Thanks! why this excellent/useful module is not introduced into Core modules yet?




      I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

        Because it's intended to be "forward compatible", i.e. you should use the latest version of Syntax::Construct from CPAN as it knows about the versions of Perl that are newer than your current Perl version. (It's still possible to update core modules from CPAN, but I fear it's not that common).

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: how check the first release of a new operand?
by haukex (Bishop) on Dec 07, 2020 at 22:00 UTC

    One more very simple way to do this that I regularly use is to install a bunch of Perl versions using perlbrew and then run a simple test using e.g. perlbrew exec perl -wMstrict -e 'my $x="foobar"; $x=~s/^foo\Kbar$/x/; die unless $x eq "foox"'. This will allow you to very quickly test how code behaves on different Perl releases. (If you wanted to dig much deeper for the development history, you could bisect the source code.)

Re: how check the first release of a new operand? (perlvers )
by Anonymous Monk on Dec 07, 2020 at 10:54 UTC
    perlver The Perl Minimum Version Analyzer Modules Perl::MinimumVersion Find a minimum required version of perl for Perl code

      Both perlver (from Perl::MinimumVersion) and perlver-fast (from Perl::MinimumVersion::Fast, which is much faster, but requires perl-5.8.0 and up) are extremely useful, but both lack some covarage, and I personally miss support for -e.

      Another problem is that both only report a single issue:

      $ cat test.pl #!/usr/bin/perl use strict; use warnings; # Requires 5.6.0 my $a = 5; -e -f -s $0 and print "0\n"; # Requires 5.8.0 1 < $a < 10 and print "1\n"; # Requires 5.31.11 / 5.32.0 $a //= 42; # Requires 5.10.0 $a =~ s{0\K}{}; # Requires 5.10.0 $b = $a =~ s{0}{1}r; # Requires 5.14.0 $ perlver --blame test.pl ------------------------------------------------------------ File : test.pl Line : 12 Char : 12 Rule : _regex Version : 5.013002 ------------------------------------------------------------ s{0}{1}r ------------------------------------------------------------

      perlver-fast does not support --blame :(

      $ perlver-fast test.pl test.pl: 5.010

      If you replace the script of perlver-fast with this code:

      #!/usr/bin/env perl use strict; use warnings; use Getopt::Long qw(:config bundling passthrough); use Perl::MinimumVersion::Fast; GetOptions ( "e:s" => \my $expr, "v" => \my $verbose, ) or die; if (@ARGV) { report ($_, $_) for @ARGV; } elsif ($expr) { report ("-e", \$expr); } else { my $src = do { local $/; <> }; report ("STDIN", \$src); } sub report { my ($in, $src) = @_; my $v = Perl::MinimumVersion::Fast->new ($src); printf "%s: %s / %s\n", $in, $v->minimum_version, $v->minimum_synt +ax_version; $verbose or return; my @markers = $v->version_markers; while (@markers) { my ($pv, $m) = splice @markers, 0, 2; printf "%-10s %s\n", $pv, $_ for @$m; } }

      You have support for -e:

      $ perlver-fast -e '$a //= 4' -e: 5.010 / 5.010

      where it would otherwise fail with Unknown file: -e at ...

      With this modified version you can also show the reasons (with -v)

      $ perlver-fast -ve '$a //= 4; package foo 0.04 { 1; }' -e: 5.014 / 5.014 5.010 //= operator 5.012 package NAME VERSION 5.014 package NAME VERSION BLOCK

      It however does not (yet) detect \K or s{}{}r (issues are created)

      $ perlver-fast -ve '$a = "fo" =~ s{f\K}{o}r' -e: 5.006 / 5.006

      Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11124766]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-09-28 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?