Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Perl 5.14 for Pragmatists

Perl 5.14 for Pragmatists

Every new release of Perl comes with a big list of changes, plenty of which seem carefully worded to make the average Perl programmer wonder, “Wait, do I care about this? What the heck is the global interpreter phase?” Perl 5.14 is chocked full of great improvements will actually be useful in day to day programming, and this talk focuses on those, leaving the weird esoterica for another day.

Ricardo Signes

June 28, 2011
Tweet

More Decks by Ricardo Signes

Other Decks in Programming

Transcript

  1. perlhist 5.14 - after 5.8, we had to wait 5

    years for 5.10 - 5.12 came out 2 years after 5.10
  2. perlhist 5.14 - after 5.8, we had to wait 5

    years for 5.10 - 5.12 came out 2 years after 5.10 - 5.14 came out 1 year after 5.12
  3. perlhist 5.14 - after 5.8, we had to wait 5

    years for 5.10 - 5.12 came out 2 years after 5.10 - 5.14 came out 1 year after 5.12 - 5.16 will come 1 year from 5.14
  4. perlhist 5.14 - 5.10 was a huge set of changes

    (too many!) - 5.12 was a lot smaller
  5. perlhist 5.14 - 5.10 was a huge set of changes

    (too many!) - 5.12 was a lot smaller - 5.14 is in between
  6. perlhist 5.14 - 5.10 was a huge set of changes

    (too many!) - 5.12 was a lot smaller - 5.14 is in between - just right?
  7. perl5140delta 5.14 is a Mixed Bag - this talk isn’t

    just for beginners - some of these changes are at the edges
  8. perl5140delta 5.14 is a Mixed Bag - this talk isn’t

    just for beginners - some of these changes are at the edges - but they’re all practical
  9. perl5140delta 5.14 is a Mixed Bag - this talk isn’t

    just for beginners - some of these changes are at the edges - but they’re all practical - except for the ones that aren’t
  10. perl5150delta By the way, 5.16... - ...and beyond are going

    to be interesting - stick around right here after the break and hear Jesse “Double Pumpking” Vincent talk about it
  11. perlpolicy ...and 5.10 is EOL - we accept critical bugfixes

    for 2 maint tracks - that’s now 5.14 and 5.12
  12. perlpolicy ...and 5.10 is EOL - we accept critical bugfixes

    for 2 maint tracks - that’s now 5.14 and 5.12 - we do security fixes for releases in last 3 years
  13. perlpolicy ...and 5.10 is EOL - we accept critical bugfixes

    for 2 maint tracks - that’s now 5.14 and 5.12 - we do security fixes for releases in last 3 years - 5.10 was 2007; it gets no promise of support
  14. perlpolicy ...and 5.10 is EOL - we accept critical bugfixes

    for 2 maint tracks - that’s now 5.14 and 5.12 - we do security fixes for releases in last 3 years - 5.10 was 2007; it gets no promise of support - if you’re still on 5.8, you’re in the weeds
  15. feature First: A Warning - 5.14 is backwards compatible -

    but has some new behaviors - they’re not all enabled by default; feature.pm
  16. feature First: A Warning - 5.14 is backwards compatible -

    but has some new behaviors - they’re not all enabled by default; feature.pm - no new feature.pm features in 5.14!
  17. feature First: A Warning - 5.14 is backwards compatible -

    but has some new behaviors - they’re not all enabled by default; feature.pm - no new feature.pm features in 5.14! I’m a perldoc ref!
  18. feature First: A Warning - 5.14 is backwards compatible -

    but has some new behaviors - they’re not all enabled by default; feature.pm - no new feature.pm features in 5.14!
  19. perlsyn - modules deprecated in 5.12 are gone in 5.14

    - you’ll have to install them from CPAN Stuff That’s Gone
  20. perlsyn - modules deprecated in 5.12 are gone in 5.14

    - you’ll have to install them from CPAN - do you care? no, because they are: Stuff That’s Gone
  21. perlsyn - modules deprecated in 5.12 are gone in 5.14

    - you’ll have to install them from CPAN - do you care? no, because they are: - Class::ISA Stuff That’s Gone
  22. perlsyn - modules deprecated in 5.12 are gone in 5.14

    - you’ll have to install them from CPAN - do you care? no, because they are: - Class::ISA - Pod::Plainer Stuff That’s Gone
  23. perlsyn - modules deprecated in 5.12 are gone in 5.14

    - you’ll have to install them from CPAN - do you care? no, because they are: - Class::ISA - Pod::Plainer - Switch Stuff That’s Gone
  24. Perl4::CoreLibs - Devel::DProf - use Devel::NYTProf instead! - the Perl

    4 core - bigrat.pl, ftp.pl, etc - Perl4::CoreLibs - Shell (again) Stuff That’s Going
  25. attributes := sub login : Local { ... } my

    $x : Private = 10; my $x := 10;
  26. attributes := sub login : Local { ... } my

    $x : Private = 10; my $x := 10;
  27. perl5140delta - those are all the things being removed -

    these are not scary removals That’s it!
  28. perlre New Regex Modifiers my @short_names = map { my

    $x = $_; $x =~ s/\..*//; $x } @long_names;
  29. perlre New Regex Modifiers /u - use Unicode rules \d

    matches BENGALI DIGIT FOUR \w matches LATIN SMALL LETTER ETH
  30. perlre New Regex Modifiers /u - use Unicode rules \d

    matches BENGALI DIGIT FOUR \w matches LATIN SMALL LETTER ETH “\N{LATIN SMALL LIGATURE FF}” =~ /ff/ui
  31. perlre New Regex Modifiers /a - Unicode, but ASCII rules

    for classes \d rejects BENGALI DIGIT FOUR \w rejects LATIN SMALL LETTER ETH “\N{LATIN SMALL LIGATURE FF}” =~ /ff/ai
  32. perlre New Regex Modifiers /aa - Unicode, ASCII won’t match

    non-ASCII \d rejects BENGALI DIGIT FOUR \w rejects LATIN SMALL LETTER ETH “\N{LATIN SMALL LIGATURE FF}” !~ /ff/aai
  33. perlre New Regex Modifiers /aa - Unicode, ASCII won’t match

    non-ASCII \d rejects BENGALI DIGIT FOUR \w rejects LATIN SMALL LETTER ETH “\N{LATIN SMALL LIGATURE FF}” !~ /ff/aai “\N{LATIN SMALL LIGATURE FF}” !~ /\pL/aai
  34. perlre New Regex Modifiers /d - default semantics Use Unicode

    if it’s seems like it’s maybe kinda unicode or the pattern
  35. perlre New Regex Modifiers /d - default semantics Use Unicode

    if it’s seems like it’s maybe kinda unicode or the pattern uses \p or \N{...}
  36. perlre New Regex Modifiers /d - default semantics Use Unicode

    if it’s seems like it’s maybe kinda unicode or the pattern uses \p or \N{...} Otherwise, on ASCII systems use ASCII
  37. perlre New Regex Modifiers /d - default semantics Use Unicode

    if it’s seems like it’s maybe kinda unicode or the pattern uses \p or \N{...} Otherwise, on ASCII systems use ASCII Otherwise, on EBCDIC systems use Latin-1
  38. perlre New Regex Modifiers /d - duhhhh-derrrrr semantics Use Unicode

    if it’s seems like it’s maybe kinda unicode or the pattern uses \p or \N{...} Otherwise, on ASCII systems use ASCII Otherwise, on EBCDIC systems use Latin-1
  39. perlre New Regex Modifiers # To be really ASCII-only: die

    “funny un-American characters” if $str =~ /\P{ASCII}/; $str =~ /...actual pattern.../;
  40. perlunitut - Learn as much as you can! - Seriously!

    - Decode user input, encode output What should I do??
  41. perlunitut - Learn as much as you can! - Seriously!

    - Decode user input, encode output - use re ‘/aa’ What should I do??
  42. perlunitut - Learn as much as you can! - Seriously!

    - Decode user input, encode output - use re ‘/aa’ - use the \p_ classes What should I do??
  43. perlunitut - Learn as much as you can! - Seriously!

    - Decode user input, encode output - use re ‘/aa’ - use the \p_ classes - But mostly: learn more. What should I do??
  44. perlunitut - “unicode_strings” feature is improved - \N{...} understands abbreviations,

    does named sequences - ...and you can make your own - better support for surrogates and non- characters More Unicode!
  45. perl5120delta - local works more better - assigning to $[

    gets a warning - each works on arrays Stuff From 5.12
  46. perl5140delta - local works even more betterer - assigning to

    ($[) gets a warning That Stuff in 5.14
  47. perl5140delta - local works even more betterer - assigning to

    ($[) gets a warning - each works on arrayrefs That Stuff in 5.14
  48. perlfunc each on arrayrefs my @array = qw( foo bar

    baz ) ; while (my ($k, $v) = each @array) { say “$k: $v”; }
  49. perlfunc each on arrayrefs my @array = qw( foo bar

    baz ) ; while (my ($k, $v) = each @array) { say “$k: $v”; } 0: foo 1: bar 2: baz
  50. perlfunc each on arrayrefs my $array = [ qw( foo

    bar baz ) ]; while (my ($k, $v) = each $array) { say “$k: $v”; } 0: foo 1: bar 2: baz
  51. perlfunc each on arrayrefs my ($x, $y) = each @{

    $h->{foo}[1] } my ($x, $y) = each $h->{foo}[1]
  52. perlfunc built-ins on references push $arrayref pop $arrayref shift $arrayref

    unshift $arrayref splice $arrayref keys $arrayref
  53. perlfunc built-ins on references push $arrayref pop $arrayref shift $arrayref

    unshift $arrayref splice $arrayref keys $arrayref values $arrayref
  54. perlfunc built-ins on references push $arrayref pop $arrayref shift $arrayref

    unshift $arrayref splice $arrayref keys $arrayref values $arrayref each $arrayref
  55. perlfunc built-ins on references push $arrayref pop $arrayref shift $arrayref

    unshift $arrayref splice $arrayref keys $arrayref values $arrayref each $arrayref keys $hashref
  56. perlfunc built-ins on references push $arrayref pop $arrayref shift $arrayref

    unshift $arrayref splice $arrayref keys $arrayref values $arrayref each $arrayref keys $hashref values $hashref
  57. perlfunc built-ins on references push $arrayref pop $arrayref shift $arrayref

    unshift $arrayref splice $arrayref keys $arrayref values $arrayref each $arrayref keys $hashref values $hashref each $hashref
  58. perlfunc built-ins on references push $arrayref pop $arrayref shift $arrayref

    unshift $arrayref splice $arrayref keys $arrayref values $arrayref each $arrayref keys $hashref values $hashref each $hashref EXPERIMENTAL
  59. perlfunc built-ins on references sub demo (+$) { my ($x,

    $y) = @_; # do stuff } demo( @array, $n );
  60. perlfunc built-ins on references sub demo (+$) { my ($x,

    $y) = @_; # do stuff } demo( @array, $n ); demo(\@array, $n );
  61. perlfunc built-ins on references sub demo (+$) { my ($x,

    $y) = @_; # do stuff } demo( @array, $n ); demo(\@array, $n ); demo( %hash, $n );
  62. perlfunc built-ins on references sub demo (+$) { my ($x,

    $y) = @_; # do stuff } demo( @array, $n ); demo(\@array, $n ); demo( %hash, $n ); demo(\%hash, $n );
  63. perlmodlib Speaking of Packages - Perl 5.14 removed a bunch

    of modules - ...so there was room to add new ones!
  64. HTTP::Tiny HTTP::Tiny use 5.14.0; use HTTP::Tiny; my $http = HTTP::Tiny->new;

    my $res = $http->get( $url ); print $res->{content} if $res->{success};
  65. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’;
  66. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new;
  67. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new; my $json = $http->get( $moose );
  68. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new; my $json = $http->get( $moose ); die $json->{reason} unless $json->{success};
  69. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new; my $json = $http->get( $moose ); die $json->{reason} unless $json->{success}; my $dist = decode_json( $json );
  70. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new; my $json = $http->get( $moose ); die $json->{reason} unless $json->{success}; my $dist = decode_json( $json ); my $tgz = $http->get( $json->{download_url} );
  71. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new; my $json = $http->get( $moose ); die $json->{reason} unless $json->{success}; my $dist = decode_json( $json ); my $tgz = $http->get( $json->{download_url} ); die $tgz->{reason} unless $tgz->{success};
  72. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new; my $json = $http->get( $moose ); die $json->{reason} unless $json->{success}; my $dist = decode_json( $json ); my $tgz = $http->get( $json->{download_url} ); die $tgz->{reason} unless $tgz->{success}; open my $fh, ‘>’, $dist->{archive};
  73. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new; my $json = $http->get( $moose ); die $json->{reason} unless $json->{success}; my $dist = decode_json( $json ); my $tgz = $http->get( $json->{download_url} ); die $tgz->{reason} unless $tgz->{success}; open my $fh, ‘>’, $dist->{archive}; $fh->print( $tgz->{content} );
  74. JSON::PP use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new; my $json = $http->get( $moose ); die $json->{reason} unless $json->{success}; my $dist = decode_json( $json ); my $tgz = $http->get( $json->{download_url} ); die $tgz->{reason} unless $tgz->{success}; open my $fh, ‘>’, $dist->{archive}; $fh->print( $tgz->{content} ); $fh->close;
  75. IO::File use 5.14.0; use autodie; use HTTP::Tiny; use JSON::PP; my

    $moose = ‘http://api.metacpan.org/release/Moose’; my $http = HTTP::Tiny->new; my $json = $http->get( $moose ); die $json->{reason} unless $json->{success}; my $dist = decode_json( $json ); my $tgz = $http->get( $json->{download_url} ); die $tgz->{reason} unless $tgz->{success}; open my $fh, ‘>’, $dist->{archive}; $fh->print( $tgz->{content} ); $fh->close;
  76. perlopentut IO::File open my $fh, ‘<’, $some_filename or die “can’t

    open fh: $!”; print {$fh} “Some output.”; close $fh or die “can’t close fh: $!”;
  77. autodie IO::File use 5.10.1; use autodie; open my $fh, ‘>’,

    $some_filename; print {$fh} “Some output.”; close $fh;
  78. IO::File IO::File use 5.10.1; use autodie; use IO::File; open my

    $fh, ‘>’, $some_filename; $fh->print( “Some output.” ); $fh->close;
  79. IO::File IO::File use 5.14.0; use autodie; use IO::File; open my

    $fh, ‘>’, $some_filename; $fh->print( “Some output.” ); $fh->close;
  80. IO::File IO::File use 5.14.0; use autodie; open my $fh, ‘>’,

    $some_filename; $fh->print( “Some output.” ); $fh->close;
  81. IO::File IO::File use 5.14.0; use autodie; open my $fh, ‘>’,

    $some_filename; $fh->print( “Some output.” ); $fh->close or die “can’t close: $!”;
  82. Try::Tiny $@ - Well, actually, you use Try::Tiny, right? -

    But this makes Try::Tiny more reliable, too!
  83. Try::Tiny $@ - Well, actually, you use Try::Tiny, right? -

    But this makes Try::Tiny more reliable, too! - You see, eval and $@ are totally awful
  84. perlfunc use 5.12.0; { package X; sub DESTROY { eval

    { } } } eval { my $x = bless {} => ‘X’; die “DEATH!!”; }; warn “ERROR: $@”;
  85. perlfunc use 5.12.0; { package X; sub DESTROY { eval

    { } } } eval { my $x = bless {} => ‘X’; die “DEATH!!”; }; warn “ERROR: $@”; $ perl5.12.4 test.pl ERROR:
  86. perlfunc use 5.14.0; { package X; sub DESTROY { eval

    { } } } eval { my $x = bless {} => ‘X’; die “DEATH!!”; }; warn “ERROR: $@”;
  87. perlfunc use 5.14.0; { package X; sub DESTROY { eval

    { } } } eval { my $x = bless {} => ‘X’; die “DEATH!!”; }; warn “ERROR: $@”; $ perl5.14.1 test.pl ERROR: DEATH!!
  88. Socket IPv6 Support! - IPv4 is getting pretty old -

    not a big deal - won’t run out of addresses until 2011-04-15
  89. Socket IPv6 Support! - IPv4 is getting pretty old -

    not a big deal - won’t run out of addresses until 2011-04-15 - …the future!
  90. perlre # Pretend there are 15 captures: qr{ (1) (2)

    (3) (4) \7 \10 (5) (6) (7) (8) (9) \7 \10 (10) \7 \10 }x;
  91. perlre # Pretend there are 15 captures: qr{ (1) (2)

    (3) (4) \o{7} \o{10} (5) (6) (7) (8) (9) \o{7} \o{10} (10) \g{7} \g{10} }x;
  92. perlsyn my @hex = (0x0D, 0x0A); my @bin = (0b1101,

    0b1010); my @hex = (0X0D, 0X0A); my @bin = (0B1101, 0B1010);
  93. perlfunc printf “%hhu\n”, 10; # char printf “%tu\n”, 10; #

    ptrdiff_t printf “%zu\n”, 10; # size_t