What's new in Perl 5.12

Sébastien Aperghis-Tramoni, sebastien@aperghis.net

Perl 5.12

  • 5.8.8 - 31 January 2006

  • 5.10.0 - 18 December 2007, 20th birthday of Perl 1.000

  • 5.8.9 - 14 December 2008

  • 5.10.1 - 23 August 2009

  • 5.12.0 - 12 April 2010

  • 5.12.1 - 16 May 2010

Perl 5.12

  • talk by Nicholas Clark in YAPC::Europe 2004, Belfast

  • Why Perl 5.8.6 is boring (and why you should be excited by this)

  • Perl 5.12.. actually "boring"

Syntax - ...

  • the yada yada operator: ...

  • placeholder for code that is not yet implemented

  • throws an exception with the text "Unimplemented"

  •     sub shortest_path {
            my (@hops) = @_;
    
            # solve the corresponding salesman problem
            ...
        }
  • do not confuse with ... (range operator) nor with ... (flip-flop)

Syntax - each

  • now works on arrays

  •     @a = qw< paff zap thwapp >;
    
        while (my ($key, $value) = each @a) {
            print "$key : $value\n"
        }
  •     0 : paff
        1 : zap
        2 : thwapp

Syntax - delete local

  • locally delete a hash entry

  •     $, = " ";
        %color = ( red => "#FF0000", green => "#00FF00", blue => "#0000FF" );
    
        print %color;
    
        {
            delete local $color{red};
            print %color;
        }
    
        print %color
  •     green #00FF00 blue #0000FF red #FF0000
        green #00FF00 blue #0000FF
        green #00FF00 blue #0000FF red #FF0000

Syntax - modules version

  • package App::Whatever v1.42.0

  • parsed at compile time, exactly the same way as use NAME VERSION

  • $VERSION is an object, and requires a new, "strict" version number format

Syntax - modules version

  • formalisation of version number formats

  • strict format: positive decimal number without exponentiation (1.42), or dotted-decimal v-string with a leading "v" and at least three components (v1.23.45)

  • lax format: v-strings may lack the leading "v" or may have less than three components; trailing alpha component, separated by underscore, is allowed (1.42_03)

  • version::is_strict() and version::is_lax()

Syntax - postfixed when

  •     given ($something) {
            $abc    = 1 when /^abc/;
            $just_a = 1 when /^a/;
            $other  = 1;
        }
  •     for (@names) {
            admin($_)   when [ qw< Alice Bob > ];
            regular($_) when [ qw< Chris David Ellen > ];
        }

Syntax - context in when

  • flip-flop operators .. and ... now evaluated in boolean context

  •     when (/^=begin/ .. /^=end/) {
            # ...
        }
  • when (expr1 // expr2) now treated as boolean if expr1 is boolean

Regexps - \N

  • reverse of \n

  • do not confuse with \N{name}

    • (as a consequence, numbers and things like "3,4" no longer are valid names)

Pragmas - implicit strictures

  • use 5.12.0

  • implicitly loads use strict and use features ':5.12'

Pragmas - new warnings

  • deprecated features now warn by default

  • no warnings "deprecated" to disable

  • numerous new warnings and diagnostics

Y2038 compliance

  • internal time-related functions now are Y2038 compliant

  • see also Time::y2038 on the CPAN

Optimisations

  • isa() a bit faster thanks to an internal cache

  • C3 linearisation 40% faster for classes with single inheritance

  • empty DESTROY methods now ignored

  • keys on empty hash now faster

  • if (%hash) now faster than if (keys %hash)

  • in-place array reversing (@a = reverse @a) now orders of magnitude faster

Unicode

  • Unicode 5.2.0

  • handling of every Unicode character property (see perluniprops)

Advanced features

  • qr// overloading

  • pluggable keywords thanks to a specific API

    • see XS::APItest::KeywordRPN for an example

  • DTrace support

New modules

  • autodie

  • Compress::Raw::Bzip2

  • parent

Updated modules

  • Archive::Tar, Attribute::Handlers, B::Deparse, CGI,

  • Compress::Raw::Zlib, CPAN, CPANPLUS, Devel::PPPort,

  • Encode, ExtUtils::MakeMaker, Module::Build,

  • Module::Pluggable, mro, Pod::Simple, threads,

  • Test::Harness, Test::Simple, version

  • ...

Loads of minor changes

  • 87 KB - perl5120delta.pod

  • 5 KB - perl586delta.pod

  • 53 KB - perl5100delta.pod

  • 112 KB - perl58delta.pod

  • 105 KB - perl56delta.pod

  • 122 KB - perl561delta.pod

Questions?

Thanks