18
Perl 5.16 new features Pavel Vlasov, 2012 Perl Mova Kiev, Ukraine

Perl 5.16 new features

Embed Size (px)

DESCRIPTION

Perl 5.16 new features, YAPC::Russia «May Perl + Perl Mova» Kiev, 12–13 May 2012

Citation preview

Page 1: Perl 5.16 new features

Perl 5.16 new features

Pavel Vlasov, 2012

Perl Mova Kiev, Ukraine

Page 2: Perl 5.16 new features

Content

1.Perl 5.16 coming

2.Unicode features

3.Other features

4.New documentation

5.Performance

Page 3: Perl 5.16 new features

1. Perl 5.16 coming

• Development of Perl 5 (1994 – now)

- 18 years

• Release date of Perl 5.16

- 16 may 2012 (in next few days)

Page 4: Perl 5.16 new features

1. Perl 5.16 coming

• Perl 5.14 – 14 may 2011

• Perl 5.16 – 16 may 2012

…....

• Perl 5.30 – 30 may 2026

• Perl 5.32 - ?????

Page 5: Perl 5.16 new features

2. Unicode features

• fc (fold case)

• quotameta

• unicode_eval

• evalbytes

Page 6: Perl 5.16 new features

2. Fold case

• Compare strings non-unicode

uc($string1) eq = uc($string2)

$string1 = ‘A’; $string2 = ‘a’;

uc(‘A’) = A uc(‘a) =A

Result: OK

$string1 = ‘ß’;

uc(‘ß’) = ‘SS’

It’s NOT OK

Page 7: Perl 5.16 new features

2. Fold case

• Compare strings in unicode

use feature ‘fc’;

fc($unicode1) eq fc($unicode2)

• Use casefolding

• inside a double-quoting string - "\F$variable"

Page 8: Perl 5.16 new features

2. quotameta

• In Perl 5.16 adopted a Unicode-defined strategy for quoting non-ASCII characters

my $string = ‘Perl May 2011 in Moscow';my $substr = ‘May.*?Moscow';$string =~ s{\Q$substr\E}{Mova 2012 in Kiev};

• Or:

use feature ‘unicode_strings’;

my $string = ‘Perl May 2011 in Moscow';my $substr = ‘May.*?Moscow';my $quoted_substr = quotemeta($substr);$string =~ s{$quoted_substr}{Mova 2012 in Kiev};

Page 9: Perl 5.16 new features

2. unicode_eval, evalbytes

unicode_eval default feature of Perl 5.16

eval – evaluate string of characters

evalbytes – die if the string contains any characters outside the 8-bit range

Page 10: Perl 5.16 new features

3. Other features

• current sub __SUB__

• CORE namespace

• array base

• debugger

Page 11: Perl 5.16 new features

3. Current sub

• current_sub (__SUB__) - reference to the current subroutine or undef outside of subroutine

• easier to write recursive closures.

use feature ‘current_sub’;

sub closure {

my $init = shift;

return sub {

state $counter = $init;

return if $counter++ > 10;

__SUB__->();

}

}

Page 12: Perl 5.16 new features

3. CORE Namespace

• Namespace for Perl’s core routines

• Give access to the original built-in of Perl

use v5.16;

or

use feature ‘say’;

or

CORE::say “yes”;

Page 13: Perl 5.16 new features

3. array base

• special variable for array base

• The 'array_base' feature replace variable $[

• $[ affected also string not only arrays

use feature ‘array_base’;

$[ = 1;

Page 14: Perl 5.16 new features

3. debugger

• Tracing mode (t command) accept number of

subroutine for trace

• Breakpoints with file names

$ b [file]:[line] [condition]

$ b lib/MyModule.pm:237 $x > 30

Page 15: Perl 5.16 new features

4. New documentation

• perldtrace

• perlexperiment

• perlootut

• perlxstypemap

Page 16: Perl 5.16 new features

5. Performance

� Improved performance for Unicode properties in regexp

� local $_ is faster now

� More? perl5160delta.pod

Page 17: Perl 5.16 new features

Used resources

• Perl5160delta.pod

• www.effectiveperlprogramming.com

• Mailing list of p5p

Page 18: Perl 5.16 new features

Thank you for attention!

[email protected]