What's new in 5.18.0?

[ Perl tips index ]
[ Subscribe to Perl tips ]

Perl 5's yearly release rhythm is well established. Because major releases come out every single year, a major release no longer introduces a slew of new features. Instead, it consists of a smaller set of features and bug fixes. Upgrading to a new major version is easier than it's ever been.

On 18th May 2013, Perl 5.18.0 was released.

What has changed?

More information

In addition to this tip you may find it useful to read the perldelta document as well as our earlier tip on What's New in 5.12, 5.14 and 5.16

Smart-match, given/when, lexical $_ all moved to experimental

There's now a new warnings category called "experimental". If you use an experimental feature without disabling that warning, you'll be told it's experimental. This allows developers to introduce new ideas and see whether they end up with unexpected consequences. Things that work will be removed from being experimental in a later release.

On the other hand, some ideas that have ended up with much confusion have been marked as experimental until this confusion is clarified.

Due to various special-casing, smart-match (and given/when as a result) and, separately, lexical $_ have been marked as experimental. Turn off these warnings with the following:

    no warnings "experimental::smartmatch";
    no warnings "experimental::lexical_topic";

or

    no warnings qw(experimental::smartmatch experimental::lexical_topic);

The special warnings IDs for each experimental feature, are included with their warnings in perldiag

Hash overhaul

In brief, hash ordering is now actually random for all hashes (as we've been told for a long while, but which hasn't always been strictly the case). Thus:

    my %hash1 = ( a => 1, b => 2, c => 3);
    my %hash2 = %hash1;

    say join " ", keys %hash1;
    say join " ", keys %hash2;

would have previously printed out identical key ordering for both hashes during each program run. This will no longer occur.

Unicode

Perl now supports Unicode 6.2.

You can also define your own names for characters for use in \N{}, although if you begin a name with a digit or include commas in the name etc, then that's a syntax error.

Set operations

You can do set operations (such as intersection) within regular expressions character classes, for example:

    no warnings "experimental::regex_sets";
    /(?[ \p{Thai} & \p{Digit} ])/

will match all the characters that are in the Thai script and are also digits. It's experimental, so you may want to turn the warning off.

Sets can be combined further:

    /(?[ ( \p{Thai} + \p{Lao} ) & \p{Digit} ])

The union of Thai and Lao scripts intersected with digits gives us all digits in Thai and Lao scripts.

See more at perlrecharchass

$^{LAST_FH}

Should you ever want access to most recently read filename, you can now use $^{LAST_FH}

    # read a line from a random (hopefully opened) file handle
    my $string = < $file_handles[ rand @file_hands ] >; 

    # oops, we want another line from that file, too
    if( length $string < MAX_LEN ) {
        $string .= < $^{LAST_FH} >;
    }

Lexical subroutine

It's been possible to create lexical subroutines of a type using subroutine references:

    my $sub = sub {
        ...
    };

    $sub->();

Now it's possible (experimentally) to create lexical, shared and static subroutines directly that are only available within the appropriate scope and only after that declaration:

    no warnings "experimental::lexical_subs";
    use feature 'lexical_subs';

    my sub lexical { ... }
    our sub shared { ... }
    state sub static { ... }

For more check out perlsub.

Neat fixes

qw(...) can no longer be used as parentheses

You can no longer write:

    foreach my $foo qw(a b c d e) {
        ...
    }

you must now enclose the qw() within parentheses:

    foreach my $foo ( qw(a b c d e) ) {
        ...
    }

require dies for unreadable files

Previously if you attempted to require a file and the file existed but was not readable in your specified location, require would ignore the file and search @INC. Now it does not.

Other things

There are a few module changes, deprecations and selected bug-fixes as well. Check the perldelta document for more.

[ Perl tips index ]
[ Subscribe to Perl tips ]


This Perl tip and associated text is copyright Perl Training Australia. You may freely distribute this text so long as it is distributed in full with this Copyright noticed attached.

If you have any questions please don't hesitate to contact us:

Email: contact@perltraining.com.au
Phone: 03 9354 6001 (Australia)
International: +61 3 9354 6001

Valid XHTML 1.0 Valid CSS