Friday 16 April 2010

perl 5.12 is out


== perl 5.12 ==

[http://search.cpan.org/~jesse/perl-5.12.0/pod/perl5120delta.pod]

many of the changes where already added in 5.10.1

but a few new things:

* strict by default if 5.12 asked
: use 5.12.0;
: # it adds the 'use strict'

* $VERSION could be defined in the 'package line'
: package Foo::Bar 1.23;

* unicode
: uses Unicode 5.2,

* \N experimental regex escape
: the contrary to \n (it could class with the unicode \N{name} this is
: the reason why it is experimental)

* each
: each could now operate on arrays

* delete local
: delete local now allows you to locally delete a hash entry.



* yada yada operator
: http://search.cpan.org/~jesse/perl-5.12.0/pod/perlop.pod#Yada_Yada_Operator___
[copy from perlop.pod]
The yada yada operator (noted ...) is a placeholder for code. Perl parses it without error, but when you try to execute a yada yada, it throws an exception with the text Unimplemented:
sub unimplemented { ... }
        
        eval { unimplemented() };
        if( $@ eq 'Unimplemented' ) {
          print "I found the yada yada!\n";
          }
You can only use the yada yada to stand in for a complete statement. These examples of the yada yada work:
{ ... }
        
        sub foo { ... }
        
        ...;
        
        eval { ... };
        
        sub foo {
                        my( $self ) = shift;
                        
                        ...;
                        }
                        
        do { my $n; ...; print 'Hurrah!' };
The yada yada cannot stand in for an expression that is part of a larger statement since the ... is also the three-dot version of the range operator (see "Range Operators"). These examples of the yada yada are still syntax errors:
print ...;
        
        open my($fh), '>', '/dev/passwd' or ...;
        
        if( $condition && ... ) { print "Hello\n" };
There are some cases where Perl can't immediately tell the difference between an expression and a statement. For instance, the syntax for a block and an anonymous hash reference constructor look the same unless there's something in the braces that give Perl a hint. The yada yada is a syntax error if Perl doesn't guess that the { ... } is a block. In that case, it doesn't think the ... is the yada yada because it's expecting an expression instead of a statement:
my @transformed = map { ... } @input;  # syntax error
You can use a ; inside your block to denote that the { ... } is a block and not a hash reference constructor. Now the yada yada works:
my @transformed = map {; ... } @input; # ; disambiguates

        my @transformed = map { ...; } @input; # ; disambiguates

No comments: