Perl 5 whats new?
Perl 5.10for people who are not totally insane
Perl 5.12  for everyday use
Perl 5.14  for pragmatists
Perl 5.16for the working programmer
Lexical Semantics!
use feature ‘say’;say “This is a test!”;{    no feature ‘say’;    say “This is fatal!”;}
use 5.16.0;say “This is a test!”;{    no feature ‘say’;    say “This is fatal!”;}
#!/usr/bin/perluse strict;use warnings;use 5.16.0; # use feature ‘:5.16’;my $x = Reticulator->new;$x->reticulate(@splines);
#!/usr/bin/perluse strict;use warnings;            # no feature;my $x = Reticulator->new;$x->reticulate(@splines);
#!/usr/bin/perluse strict;use warnings;            # use feature ‘:default’my $x = Reticulator->new;$x->reticulate(@spline...
array_base: $[
Cool New Features!
Better Error Message(s)$str = “Greetings, $name. Your lastlogin was $last. It is now $time.”;                             ...
Better Error Message(s)$str = “Greetings, $name. Your lastlogin was $last. It is now $time.”;Use of uninitialized value in...
Better Error Message(s)$str = “Greetings, $name. Your lastlogin was $last. It is now $time.”;Use of uninitialized value $t...
State Variablesmy $LINES_READ = 0;sub read_line {  $LINES_READ++;    ...}                            perlsub
State Variables{    my $LINES_READ = 0;    sub read_line {      $LINES_READ++;        ...    }}                           ...
State Variablessub read_line {  state $LINES_READ = 0;    $LINES_READ++;    ...}                           perlsub
truth and definedness                        perlop
truth and definednesssub record_sale {                          perlop
truth and definednesssub record_sale {  my ($product, $amount) = @_;                             perlop
truth and definednesssub record_sale {  my ($product, $amount) = @_; my $price = $amount                             perlop
truth and definednesssub record_sale {  my ($product, $amount) = @_; my $price = $amount          || $product->price;     ...
truth and definednesssub record_sale {  my ($product, $amount) = @_; my $price = $amount          || $product->price; ... ...
truth and definednesssub record_sale {  my ($product, $amount) = @_;    my $price = $amount             || $product->price...
truth and definednesssub record_sale {  my ($product, $amount) = @_;    $price = defined $amount           ? $amount      ...
truth and definednesssub record_sale {  my ($product, $amount) = @_;    my $price = $amount             || $product->price...
truth and definednesssub record_sale {  my ($product, $amount) = @_;    my $price = $amount             // $product->price...
the new OR operatorsub record_sale {  my ($product, $amount) = @_;    $amount //= $product->cost;    ...}                 ...
say $what- new built-in, say- it’s like print- but it adds a newline for you                                  perlfunc
say $what            perlfunc
say $whatprint “Hello, world!n”;                           perlfunc
say $whatprint “Hello, world!n”;print “$messagen”;                           perlfunc
say $whatprint “Hello, world!n”;print “$messagen”;print “$_n” for @lines;                           perlfunc
say $whatprint “Hello, world!n”;say “Hello, world!”;print “$messagen”;print “$_n” for @lines;                           pe...
say $whatprint “Hello, world!n”;say “Hello, world!”;print “$messagen”;say $message;print “$_n” for @lines;                ...
say $whatprint “Hello, world!n”;say “Hello, world!”;print “$messagen”;say $message;print “$_n” for @lines;say for @lines; ...
$ perl -e ‘print “Foon”’
$ perl -e ‘print “Foon”’$ perl -E ‘say “Foo”’
Recursion!sub fact {  my ($x) = @_; # must be +int  return $x if $x == 1;  return $x * fact($x - 1);}
Recursion!sub fact {  my ($x) = @_; # must be +int  return $x if $x == 1;  return $x * fact($x - 1);}
Recursion!my $fact = sub {  my ($x) = @_; # must be +int  return $x if $x == 1;  return $x * $fact->($x - 1);};
Recursion!my $fact = sub {  my ($x) = @_; # must be +int  return $x if $x == 1;  return $x * $fact->($x - 1);};
Recursion!my $fact;$fact = sub   {  my ($x) =   @_; # must be +int  return $x   if $x == 1;  return $x   * $fact->($x - 1)...
Recursion!my $fact;$fact = sub   {  my ($x) =   @_; # must be +int  return $x   if $x == 1;  return $x   * $fact->($x - 1)...
Recursion!use Scalar::Util qw(weaken);my $fact = do {  my $f1;  my $f2 = $f1 = sub {    my ($x) = @_;    return $x if $x =...
Recursion!use 5.16.0; # current_submy $fact = sub {  my ($x) = @_; # must be +int  return $x if $x == 1;  return $x * __SU...
Filehandles!
autodieopen my $fh, ‘<‘, $filename;while (<$fh>) {  ...}close $fh;                               autodie
autodieopen my $fh, ‘<‘, $filename  or die “couldn’t open $filename: $!”;while (<$fh>) {  ...}close $fh  or die “couldn’t ...
autodieuse autodie;open my $fh, ‘<‘, $filename;while (<$fh>) {  ...}close $fh;                               autodie
autodieuse autodie;open my $fh, ‘<‘, $filename;while (<$fh>) {  no autodie;  rmdir or warn “couldn’t remove $_: $!”;}close...
autodieuse autodie;sub foo {  my $filename = shift;  open my $fh, ‘<‘, $filename;  while (<$fh>) {     ...  }} # this impl...
IO::Filesub stream_to_fh {  my ($self, $fh) = @_;    fileno $fh      or die “can’t stream to closed fh”;    while (my $hun...
IO::Filesub stream_to_fh {  my ($self, $fh) = @_;    $fh->fileno      or die “can’t stream to closed fh”;    while (my $hu...
IO::Filesub stream_to_fh {  ...    $fh->print($hunk);  ...  $fh->close or die “error closing: $!”;}open my $target, ‘>’, ‘...
IO::Fileuse IO::File;sub stream_to_fh {  ...    $fh->print($hunk);  ...  $fh->close or die “error closing: $!”;}open my $t...
IO::Fileuse 5.14.0;sub stream_to_fh {  ...    $fh->print($hunk);  ...  $fh->close or die “error closing: $!”;}open my $tar...
IO::Fileuse 5.14.0;use autodie;sub stream_to_fh {  ...    $fh->print($hunk);  ...  $fh->close or die “error closing: $!”;}...
Package Blockspackage Library::Awesome;our $VERSION = 1.234;sub foo { ... }1;                            perlfunc
Package Blocksuse 5.12.0;package Library::Awesome 1.234;sub foo { ... }1;                                  perlfunc
Package Blocksuse 5.12.0;package Library::Awesome 1.234-alpha;sub foo { ... }1;                                        per...
Package Blockspackage Library::Awesome 1.234 {    sub foo { ... }}1;                                   perlfunc
overloading- the -x overload- the qr overload- "no overloading"- unknown overload warns                           perldoc
Other New Features!
smrt match
smrt matchif ($x ~~ $y) {  ...}
smrt match             perldoc
smrt match- if $x and $y are unknown, there are 23  possible dispatch paths                                           perl...
smrt match- if $x and $y are unknown, there are 23  possible dispatch paths- and some of them redispatch recursively      ...
smrt match- if $x and $y are unknown, there are 23  possible dispatch paths- and some of them redispatch recursively- no, ...
smrt match- if $x and $y are unknown, there are 23  possible dispatch paths- and some of them redispatch recursively- no, ...
Matching
Matchingif ($x ~~ $y)       {...}
Matchingif ($x ~~ $y)        {...}if ($str ~~ %hash)   {...}
Matchingif ($x ~~ $y)        {...}if ($str ~~ %hash)   {...}if ($str ~~ @arr)    {...}
Matchingif   ($x ~~ $y)              {...}if   ($str ~~ %hash)         {...}if   ($str ~~ @arr)          {...}if   ($str ~...
Matchingif   ($x ~~ $y)            {...}if   ($str ~~ %hash)       {...}if   ($str ~~ @arr)        {...}if   ($str ~~ [ %h...
Matchingif   ($x ~~ $y)            {...}if   ($str ~~ %hash)       {...}if   ($str ~~ @arr)        {...}if   ($str ~~ [ %h...
Matchingif   ($x ~~ $y)              {...}if   ($str ~~ %hash)         {...}if   ($str ~~ @arr)          {...}if   ($str ~...
given ($x) {  when ($y) {    ...  }  when ($z) {    ...  }}
given ($x) {  when ($y) {    try   { ... }    catch {      warn “error: $_”;      return undef;    }  }}
each @array
each @arraywhile (my ($i, $v) = each @array) {  say “$i: $v”;}
push $aref, @etc;
Now With Fewer Bugs!
y2038
~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’
~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038
~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038~$ perl5.10.0 -E ‘say scalar localtime 2**31’
~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038~$ perl5.10.0 -E ‘say scalar localtime 2**31’Fri De...
~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’
~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038
~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038~$ perl5.12.0 -E ‘say scalar localtime 2**31’
~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038~$ perl5.12.0 -E ‘say scalar localtime 2**31’Mon Ja...
$@     perlvar
$@     Try::Tiny
$@- Well, actually, you use Try::Tiny, right?                                              Try::Tiny
$@- Well, actually, you use Try::Tiny, right?- But this makes Try::Tiny more reliable, too!                               ...
$@- Well, actually, you use Try::Tiny, right?- But this makes Try::Tiny more reliable, too!- You see, eval and $@ are tota...
use 5.12.0;{    package X;    sub DESTROY { eval { } }}eval {  my $x = bless {} => ‘X’;  die “DEATH!!”;};warn “ERROR: $@”;...
use 5.12.0;{    package X;    sub DESTROY { eval { } }}eval {  my $x = bless {} => ‘X’;  die “DEATH!!”;};warn “ERROR: $@”;...
use 5.14.0;{    package X;    sub DESTROY { eval { } }}eval {  my $x = bless {} => ‘X’;  die “DEATH!!”;};warn “ERROR: $@”;...
use 5.14.0;{    package X;    sub DESTROY { eval { } }}eval {  my $x = bless {} => ‘X’;  die “DEATH!!”;};warn “ERROR: $@”;...
perl -le ‘print $^X’
perl -le ‘print $^X’10.0: perl
perl -le ‘print $^X’10.0: perl10.1: perl
perl -le ‘print $^X’10.0: perl10.1: perl12.0: perl
perl -le ‘print $^X’10.0:   perl10.1:   perl12.0:   perl14.0:   perl
perl -le ‘print $^X’10.0:   perl10.1:   perl12.0:   perl14.0:   perl16.0:   /Users/rjbs/perl5/perlbrew/perls/16.0/bin/perl
Simpler Strings
Perl is Good at Unicode                     perlunicode
Perl 5.16 is Better                      perlunicode
Perl 5.16 is Better- Unicode 6.1                           perlunicode
Perl 5.16 is Better- Unicode 6.1- every character property is available                                          perlunicode
Perl 5.16 is Better- Unicode 6.1- every character property is available- X in regex is more sensible                      ...
“The Unicode Bug”                perlunicode
“The Unicode Bug”- strings aren’t always treated as Unicode                                             perlunicode
“The Unicode Bug”- strings aren’t always treated as Unicode- this causes weird bugs that take ages to find                ...
“The Unicode Bug”- strings aren’t always treated as Unicode- this causes weird bugs that take ages to find-   use feature ...
“The Unicode Bug”- strings aren’t always treated as Unicode- this causes weird bugs that take ages to find-   use feature ...
Unicode eval- eval $str- is that octets or chars?- what if it includes "use utf8"- or youre under "use utf8"?             ...
Unicode eval- evalbytes $str- unicode_eval                   perldoc
My Favorite 5.12-ism?if (length $input->{new_email}) {  $user->update_email(...);}                                    perl...
My Favorite 5.12-ism?if (length $input->{new_email}) {  $user->update_email(...);}Use of uninitialized value in lengthat -...
My Favorite 5.12-ism?if (length $input->{new_email}) {  $user->update_email(...);}                                    perl...
say “I o{23145} Perl 5.14!”;                                perlsyn
say “I o{23145} Perl 5.14!”;I ♥ Perl 5.14!                                perlsyn
say “I 23145 Perl 5.14!”;I ?45 Perl 5.14!                             perlsyn
say “I 023145 Perl 5.14!”;I 145 Perl 5.14!                              perlsyn
qr{  (1) (2) (3) (4)     7 10  (5) (6) (7) (8) (9) 7 10  (10)                7 10}x;                               perlre
qr{  (1) (2) (3) (4)     o{7} o{10}  (5) (6) (7) (8) (9) o{7} o{10}  (10)                g{7} g{10}}x;                    ...
Unicode 6.1              charnames
Unicode 6.1              charnames
Unicode 6            charnames
Unicode 6            charnames
Unicode 6            charnames
Unicode 6            charnames
Unicode 6            charnames
Unicode 6            charnames
Unicode 6            charnames
Unicode 6            charnames
Unicode 6            charnames
N{...}use 5.16.0;say “I N{HEAVY BLACK HEART} Queensr”  . “N{LATIN SMALL LETTER Y WITH DIAERESIS}”  . “che!”;
case folding
Case Foldingif (lc $foo eq lc $bar) {  ...}
Case Foldingif (fc $foo eq fc $bar) {  ...}
Case Folding
Case Foldinglc ‘ς‘ ➔ ‘ς‘
Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘
Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘
Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘lc ‘ß’ ➔ ‘ß’
Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘lc ‘ß’ ➔ ‘ß’uc ‘ß’ ➔ ‘SS’
Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘lc ‘ß’ ➔ ‘ß’uc ‘ß’ ➔ ‘SS’fc ‘ß’ ➔ ‘ss’
Case Folding
Case Folding“file under: L$name”
Case Folding“file under: L$name”“file under: F$name”
Better Regex
named captures
Regex: Named Captures                        perlre
Regex: Named Captures- find matches by name, not position                                       perlre
Regex: Named Captures- find matches by name, not position- avoid the dreaded$1                                       perlre
Regex: Named Captures- find matches by name, not position- avoid the dreaded $1- no longer second to Python or .Net!      ...
Regex: Named Captures# our hypothetical formatsection:property = value                            perlre
Regex: Named Captures$line =~ /(w+):(w+) = (w+)/;$section = $1$name    = $2;$value   = $3;                                ...
Regex: Named Captures$line =~ /  (?<section>   w+):  (?<name>      w+)  s* = s*  (?<value>     w+)/x;$section = $+{section...
New Regex Modifiersmy $hostname = get_hostname;$hostname =~ s/..*//;                               perlre
New Regex Modifiersmy $hostname = get_hostname =~ s/..*//;                                           perlre
New Regex Modifiers(my $hostname = get_hostname) =~ s/..*//;                                         perlre
New Regex Modifiersmy $hostname = get_hostname =~ s/..*//r;                                            perlre
New Regex Modifiersmy @short_names =  map { s/..*//; } @long_names;                                   perlre
New Regex Modifiersmy @short_names =  map { s/..*//;        $_ } @long_names;                            perlre
New Regex Modifiersmy @short_names =  map { my $x = $_;        $x =~ s/..*//;        $x } @long_names;                    ...
New Regex Modifiersmy @short_names =  map { s/..*//r } @long_names;                                   perlre
New Regex Modifiersmy @short_names =  map s/..*//r, @long_names;                                perlre
New Regex Modifiers                      perldoc
New Regex Modifiers                /u   /a   /aa   /d   /l"൮" =~ /d/     ✓    !    !     ¿?   ¿?"ð" =~ /w/     ✓    !    !...
New Regex Modifiers                /u   /a   /aa   /d   /l"൮" =~ /d/     ✓    !    !     ¿?   ¿?"ð" =~ /w/     ✓    !    !...
New Regex Modifiers                /u   /a   /aa   /d   /l"൮" =~ /d/     ✓    !    !     ¿?   ¿?"ð" =~ /w/     ✓    !    !...
New Regex Modifiers                /u   /a   /aa   /d   /l"൮" =~ /d/     ✓    !    !     ¿?   ¿?"ð" =~ /w/     ✓    !    !...
New Regex Modifiers                /u   /a   /aa   /d   /l"൮" =~ /d/     ✓    !    !     ¿?   ¿?"ð" =~ /w/     ✓    !    !...
New Regex Modifiers                /u   /a   /aa   /d   /l"൮" =~ /d/     ✓    !    !     ¿?   ¿?"ð" =~ /w/     ✓    !    !...
New Regex Modifiers# To be really ASCII-only:die “funny un-American characters”  if $str =~ /P{ASCII}/;$str =~ /...actual ...
study
studymy $re   = qr{...complex...};
studymy $re = qr{...complex...};my $str = q{...long complex...};
studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow!!
studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow!!study $str;   # does stuff
studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow!!study $str;   # does stuff$str =~ $re...
studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow but right!!study $str;   # does stuff$...
studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow but right!!study $str;   # does nothin...
Modder Modlib
Newly Cored Librarys- JSON- HTTP::Tiny- Module::Metadata- CPAN::Meta                     perlmodlib
Newly Ejected Librarys- Devel::DProf- Switch- the perl4 core- ...and more                    perlmodlib
Old Stuff Removed
qw()for my $show qw(Smallville Lost V)   {  $tivo->cancel_pass( $show );}                                         perlop
qw()for my $show (qw(Smallville Lost V)) {  $tivo->cancel_pass( $show );}                                         perlop
$[
$[ - first index of array                       perlvar
$[ - first index of array - so you can make $array[1] mean first                                          perlvar
$[ - first index of array - so you can make $array[1] mean first - isn’t that awesome???                                  ...
$[ - first index of array - so you can make $array[1] mean first - isn’t that awesome??? - yeah, about as awesome as Comic...
$[$[ = 1;for (1 .. $#array) {  ...}                       perlvar
$[for ($[ .. $#array) {  ...}                        perlvar
$[Assigned to $[. Are you some kind ofidiot or something? at -e line 123.                                       perlvar
$[Use of assignment to $[ is deprecatedat -e line 123.                                        perlvar
defined @arr
Any questions?
Thank you!
What's New in Perl?  v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16
Upcoming SlideShare
Loading in...5
×

What's New in Perl? v5.10 - v5.16

2,749

Published on

This talk describes the most likely-to-be-used features added to Perl 5 between v5.10 and v5.16, inclusive.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,749
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

What's New in Perl? v5.10 - v5.16

  1. 1. Perl 5 whats new?
  2. 2. Perl 5.10for people who are not totally insane
  3. 3. Perl 5.12 for everyday use
  4. 4. Perl 5.14 for pragmatists
  5. 5. Perl 5.16for the working programmer
  6. 6. Lexical Semantics!
  7. 7. use feature ‘say’;say “This is a test!”;{ no feature ‘say’; say “This is fatal!”;}
  8. 8. use 5.16.0;say “This is a test!”;{ no feature ‘say’; say “This is fatal!”;}
  9. 9. #!/usr/bin/perluse strict;use warnings;use 5.16.0; # use feature ‘:5.16’;my $x = Reticulator->new;$x->reticulate(@splines);
  10. 10. #!/usr/bin/perluse strict;use warnings; # no feature;my $x = Reticulator->new;$x->reticulate(@splines);
  11. 11. #!/usr/bin/perluse strict;use warnings; # use feature ‘:default’my $x = Reticulator->new;$x->reticulate(@splines);
  12. 12. array_base: $[
  13. 13. Cool New Features!
  14. 14. Better Error Message(s)$str = “Greetings, $name. Your lastlogin was $last. It is now $time.”; perldiag
  15. 15. Better Error Message(s)$str = “Greetings, $name. Your lastlogin was $last. It is now $time.”;Use of uninitialized value inconcatenation (.) or string athello.plx line 9. perldiag
  16. 16. Better Error Message(s)$str = “Greetings, $name. Your lastlogin was $last. It is now $time.”;Use of uninitialized value $time inconcatenation (.) or string athello.plx line 9. perldiag
  17. 17. State Variablesmy $LINES_READ = 0;sub read_line { $LINES_READ++; ...} perlsub
  18. 18. State Variables{ my $LINES_READ = 0; sub read_line { $LINES_READ++; ... }} perlsub
  19. 19. State Variablessub read_line { state $LINES_READ = 0; $LINES_READ++; ...} perlsub
  20. 20. truth and definedness perlop
  21. 21. truth and definednesssub record_sale { perlop
  22. 22. truth and definednesssub record_sale { my ($product, $amount) = @_; perlop
  23. 23. truth and definednesssub record_sale { my ($product, $amount) = @_; my $price = $amount perlop
  24. 24. truth and definednesssub record_sale { my ($product, $amount) = @_; my $price = $amount || $product->price; perlop
  25. 25. truth and definednesssub record_sale { my ($product, $amount) = @_; my $price = $amount || $product->price; ... perlop
  26. 26. truth and definednesssub record_sale { my ($product, $amount) = @_; my $price = $amount || $product->price; ...} perlop
  27. 27. truth and definednesssub record_sale { my ($product, $amount) = @_; $price = defined $amount ? $amount : $product->price; ...} perlop
  28. 28. truth and definednesssub record_sale { my ($product, $amount) = @_; my $price = $amount || $product->price; ...} perlop
  29. 29. truth and definednesssub record_sale { my ($product, $amount) = @_; my $price = $amount // $product->price; ...} perlop
  30. 30. the new OR operatorsub record_sale { my ($product, $amount) = @_; $amount //= $product->cost; ...} perlop
  31. 31. say $what- new built-in, say- it’s like print- but it adds a newline for you perlfunc
  32. 32. say $what perlfunc
  33. 33. say $whatprint “Hello, world!n”; perlfunc
  34. 34. say $whatprint “Hello, world!n”;print “$messagen”; perlfunc
  35. 35. say $whatprint “Hello, world!n”;print “$messagen”;print “$_n” for @lines; perlfunc
  36. 36. say $whatprint “Hello, world!n”;say “Hello, world!”;print “$messagen”;print “$_n” for @lines; perlfunc
  37. 37. say $whatprint “Hello, world!n”;say “Hello, world!”;print “$messagen”;say $message;print “$_n” for @lines; perlfunc
  38. 38. say $whatprint “Hello, world!n”;say “Hello, world!”;print “$messagen”;say $message;print “$_n” for @lines;say for @lines; perlfunc
  39. 39. $ perl -e ‘print “Foon”’
  40. 40. $ perl -e ‘print “Foon”’$ perl -E ‘say “Foo”’
  41. 41. Recursion!sub fact { my ($x) = @_; # must be +int return $x if $x == 1; return $x * fact($x - 1);}
  42. 42. Recursion!sub fact { my ($x) = @_; # must be +int return $x if $x == 1; return $x * fact($x - 1);}
  43. 43. Recursion!my $fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * $fact->($x - 1);};
  44. 44. Recursion!my $fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * $fact->($x - 1);};
  45. 45. Recursion!my $fact;$fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * $fact->($x - 1);};
  46. 46. Recursion!my $fact;$fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * $fact->($x - 1);};
  47. 47. Recursion!use Scalar::Util qw(weaken);my $fact = do { my $f1; my $f2 = $f1 = sub { my ($x) = @_; return $x if $x == 1; return $x * $f1->($x - 1); }; weaken($f1); $f1;};
  48. 48. Recursion!use 5.16.0; # current_submy $fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * __SUB__->($x - 1);};
  49. 49. Filehandles!
  50. 50. autodieopen my $fh, ‘<‘, $filename;while (<$fh>) { ...}close $fh; autodie
  51. 51. autodieopen my $fh, ‘<‘, $filename or die “couldn’t open $filename: $!”;while (<$fh>) { ...}close $fh or die “couldn’t close $filename: $!”; autodie
  52. 52. autodieuse autodie;open my $fh, ‘<‘, $filename;while (<$fh>) { ...}close $fh; autodie
  53. 53. autodieuse autodie;open my $fh, ‘<‘, $filename;while (<$fh>) { no autodie; rmdir or warn “couldn’t remove $_: $!”;}close $fh; autodie
  54. 54. autodieuse autodie;sub foo { my $filename = shift; open my $fh, ‘<‘, $filename; while (<$fh>) { ... }} # this implicit close DID NOT AUTODIE autodie
  55. 55. IO::Filesub stream_to_fh { my ($self, $fh) = @_; fileno $fh or die “can’t stream to closed fh”; while (my $hunk = $self->next_hunk) { print {$fh} $hunk; } close $fh or die “error closing: $!”;} perlopentut
  56. 56. IO::Filesub stream_to_fh { my ($self, $fh) = @_; $fh->fileno or die “can’t stream to closed fh”; while (my $hunk = $self->next_hunk) { $fh->print($hunk); } $fh->close or die “error closing: $!”;} perlopentut
  57. 57. IO::Filesub stream_to_fh { ... $fh->print($hunk); ... $fh->close or die “error closing: $!”;}open my $target, ‘>’, ‘/dev/null’ or die “can’t open bit bucket: $!”;stream_to_fh($target); perlopentut
  58. 58. IO::Fileuse IO::File;sub stream_to_fh { ... $fh->print($hunk); ... $fh->close or die “error closing: $!”;}open my $target, ‘>’, ‘/dev/null’ or die “can’t open bit bucket: $!”;stream_to_fh($target); perlopentut
  59. 59. IO::Fileuse 5.14.0;sub stream_to_fh { ... $fh->print($hunk); ... $fh->close or die “error closing: $!”;}open my $target, ‘>’, ‘/dev/null’ or die “can’t open bit bucket: $!”;stream_to_fh($target); perlopentut
  60. 60. IO::Fileuse 5.14.0;use autodie;sub stream_to_fh { ... $fh->print($hunk); ... $fh->close or die “error closing: $!”;}open my $target, ‘>’, ‘/dev/null’ or die “can’t open bit bucket: $!”;stream_to_fh($target); perlopentut
  61. 61. Package Blockspackage Library::Awesome;our $VERSION = 1.234;sub foo { ... }1; perlfunc
  62. 62. Package Blocksuse 5.12.0;package Library::Awesome 1.234;sub foo { ... }1; perlfunc
  63. 63. Package Blocksuse 5.12.0;package Library::Awesome 1.234-alpha;sub foo { ... }1; perlfunc
  64. 64. Package Blockspackage Library::Awesome 1.234 { sub foo { ... }}1; perlfunc
  65. 65. overloading- the -x overload- the qr overload- "no overloading"- unknown overload warns perldoc
  66. 66. Other New Features!
  67. 67. smrt match
  68. 68. smrt matchif ($x ~~ $y) { ...}
  69. 69. smrt match perldoc
  70. 70. smrt match- if $x and $y are unknown, there are 23 possible dispatch paths perldoc
  71. 71. smrt match- if $x and $y are unknown, there are 23 possible dispatch paths- and some of them redispatch recursively perldoc
  72. 72. smrt match- if $x and $y are unknown, there are 23 possible dispatch paths- and some of them redispatch recursively- no, you wont remember them all perldoc
  73. 73. smrt match- if $x and $y are unknown, there are 23 possible dispatch paths- and some of them redispatch recursively- no, you wont remember them all- ...and they cant be intuited perldoc
  74. 74. Matching
  75. 75. Matchingif ($x ~~ $y) {...}
  76. 76. Matchingif ($x ~~ $y) {...}if ($str ~~ %hash) {...}
  77. 77. Matchingif ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}
  78. 78. Matchingif ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}if ($str ~~ [ %h, ...]) {...}
  79. 79. Matchingif ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}if ($str ~~ [ %h, ...]) {...}if (%hash ~~ %h) {...}
  80. 80. Matchingif ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}if ($str ~~ [ %h, ...]) {...}if (%hash ~~ %h) {...}if (%hash ~~ @arr) {...}
  81. 81. Matchingif ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}if ($str ~~ [ %h, ...]) {...}if (%hash ~~ %h) {...}if (%hash ~~ @arr) {...}if (%hash ~~ [ %h,...]) {...}
  82. 82. given ($x) { when ($y) { ... } when ($z) { ... }}
  83. 83. given ($x) { when ($y) { try { ... } catch { warn “error: $_”; return undef; } }}
  84. 84. each @array
  85. 85. each @arraywhile (my ($i, $v) = each @array) { say “$i: $v”;}
  86. 86. push $aref, @etc;
  87. 87. Now With Fewer Bugs!
  88. 88. y2038
  89. 89. ~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’
  90. 90. ~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038
  91. 91. ~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038~$ perl5.10.0 -E ‘say scalar localtime 2**31’
  92. 92. ~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038~$ perl5.10.0 -E ‘say scalar localtime 2**31’Fri Dec 13 15:45:52 1901
  93. 93. ~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’
  94. 94. ~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038
  95. 95. ~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038~$ perl5.12.0 -E ‘say scalar localtime 2**31’
  96. 96. ~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038~$ perl5.12.0 -E ‘say scalar localtime 2**31’Mon Jan 18 22:14:08 2038
  97. 97. $@ perlvar
  98. 98. $@ Try::Tiny
  99. 99. $@- Well, actually, you use Try::Tiny, right? Try::Tiny
  100. 100. $@- Well, actually, you use Try::Tiny, right?- But this makes Try::Tiny more reliable, too! Try::Tiny
  101. 101. $@- Well, actually, you use Try::Tiny, right?- But this makes Try::Tiny more reliable, too!- You see, eval and $@ are totally awful Try::Tiny
  102. 102. use 5.12.0;{ package X; sub DESTROY { eval { } }}eval { my $x = bless {} => ‘X’; die “DEATH!!”;};warn “ERROR: $@”; perlfunc
  103. 103. use 5.12.0;{ package X; sub DESTROY { eval { } }}eval { my $x = bless {} => ‘X’; die “DEATH!!”;};warn “ERROR: $@”;$ perl5.12.4 test.plERROR: perlfunc
  104. 104. use 5.14.0;{ package X; sub DESTROY { eval { } }}eval { my $x = bless {} => ‘X’; die “DEATH!!”;};warn “ERROR: $@”; perlfunc
  105. 105. use 5.14.0;{ package X; sub DESTROY { eval { } }}eval { my $x = bless {} => ‘X’; die “DEATH!!”;};warn “ERROR: $@”;$ perl5.14.1 test.plERROR: DEATH!! perlfunc
  106. 106. perl -le ‘print $^X’
  107. 107. perl -le ‘print $^X’10.0: perl
  108. 108. perl -le ‘print $^X’10.0: perl10.1: perl
  109. 109. perl -le ‘print $^X’10.0: perl10.1: perl12.0: perl
  110. 110. perl -le ‘print $^X’10.0: perl10.1: perl12.0: perl14.0: perl
  111. 111. perl -le ‘print $^X’10.0: perl10.1: perl12.0: perl14.0: perl16.0: /Users/rjbs/perl5/perlbrew/perls/16.0/bin/perl
  112. 112. Simpler Strings
  113. 113. Perl is Good at Unicode perlunicode
  114. 114. Perl 5.16 is Better perlunicode
  115. 115. Perl 5.16 is Better- Unicode 6.1 perlunicode
  116. 116. Perl 5.16 is Better- Unicode 6.1- every character property is available perlunicode
  117. 117. Perl 5.16 is Better- Unicode 6.1- every character property is available- X in regex is more sensible perlunicode
  118. 118. “The Unicode Bug” perlunicode
  119. 119. “The Unicode Bug”- strings aren’t always treated as Unicode perlunicode
  120. 120. “The Unicode Bug”- strings aren’t always treated as Unicode- this causes weird bugs that take ages to find perlunicode
  121. 121. “The Unicode Bug”- strings aren’t always treated as Unicode- this causes weird bugs that take ages to find- use feature ‘unicode_strings’; perlunicode
  122. 122. “The Unicode Bug”- strings aren’t always treated as Unicode- this causes weird bugs that take ages to find- use feature ‘unicode_strings’;- or use 5.12.0 perlunicode
  123. 123. Unicode eval- eval $str- is that octets or chars?- what if it includes "use utf8"- or youre under "use utf8"? perldoc
  124. 124. Unicode eval- evalbytes $str- unicode_eval perldoc
  125. 125. My Favorite 5.12-ism?if (length $input->{new_email}) { $user->update_email(...);} perldiag
  126. 126. My Favorite 5.12-ism?if (length $input->{new_email}) { $user->update_email(...);}Use of uninitialized value in lengthat - line 3120. perldiag
  127. 127. My Favorite 5.12-ism?if (length $input->{new_email}) { $user->update_email(...);} perldiag
  128. 128. say “I o{23145} Perl 5.14!”; perlsyn
  129. 129. say “I o{23145} Perl 5.14!”;I ♥ Perl 5.14! perlsyn
  130. 130. say “I 23145 Perl 5.14!”;I ?45 Perl 5.14! perlsyn
  131. 131. say “I 023145 Perl 5.14!”;I 145 Perl 5.14! perlsyn
  132. 132. qr{ (1) (2) (3) (4) 7 10 (5) (6) (7) (8) (9) 7 10 (10) 7 10}x; perlre
  133. 133. qr{ (1) (2) (3) (4) o{7} o{10} (5) (6) (7) (8) (9) o{7} o{10} (10) g{7} g{10}}x; perlre
  134. 134. Unicode 6.1 charnames
  135. 135. Unicode 6.1 charnames
  136. 136. Unicode 6 charnames
  137. 137. Unicode 6 charnames
  138. 138. Unicode 6 charnames
  139. 139. Unicode 6 charnames
  140. 140. Unicode 6 charnames
  141. 141. Unicode 6 charnames
  142. 142. Unicode 6 charnames
  143. 143. Unicode 6 charnames
  144. 144. Unicode 6 charnames
  145. 145. N{...}use 5.16.0;say “I N{HEAVY BLACK HEART} Queensr” . “N{LATIN SMALL LETTER Y WITH DIAERESIS}” . “che!”;
  146. 146. case folding
  147. 147. Case Foldingif (lc $foo eq lc $bar) { ...}
  148. 148. Case Foldingif (fc $foo eq fc $bar) { ...}
  149. 149. Case Folding
  150. 150. Case Foldinglc ‘ς‘ ➔ ‘ς‘
  151. 151. Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘
  152. 152. Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘
  153. 153. Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘lc ‘ß’ ➔ ‘ß’
  154. 154. Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘lc ‘ß’ ➔ ‘ß’uc ‘ß’ ➔ ‘SS’
  155. 155. Case Foldinglc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘lc ‘ß’ ➔ ‘ß’uc ‘ß’ ➔ ‘SS’fc ‘ß’ ➔ ‘ss’
  156. 156. Case Folding
  157. 157. Case Folding“file under: L$name”
  158. 158. Case Folding“file under: L$name”“file under: F$name”
  159. 159. Better Regex
  160. 160. named captures
  161. 161. Regex: Named Captures perlre
  162. 162. Regex: Named Captures- find matches by name, not position perlre
  163. 163. Regex: Named Captures- find matches by name, not position- avoid the dreaded$1 perlre
  164. 164. Regex: Named Captures- find matches by name, not position- avoid the dreaded $1- no longer second to Python or .Net! perlre
  165. 165. Regex: Named Captures# our hypothetical formatsection:property = value perlre
  166. 166. Regex: Named Captures$line =~ /(w+):(w+) = (w+)/;$section = $1$name = $2;$value = $3; perlre
  167. 167. Regex: Named Captures$line =~ / (?<section> w+): (?<name> w+) s* = s* (?<value> w+)/x;$section = $+{section};$name = $+{name};$value = $+{value}; perlre
  168. 168. New Regex Modifiersmy $hostname = get_hostname;$hostname =~ s/..*//; perlre
  169. 169. New Regex Modifiersmy $hostname = get_hostname =~ s/..*//; perlre
  170. 170. New Regex Modifiers(my $hostname = get_hostname) =~ s/..*//; perlre
  171. 171. New Regex Modifiersmy $hostname = get_hostname =~ s/..*//r; perlre
  172. 172. New Regex Modifiersmy @short_names = map { s/..*//; } @long_names; perlre
  173. 173. New Regex Modifiersmy @short_names = map { s/..*//; $_ } @long_names; perlre
  174. 174. New Regex Modifiersmy @short_names = map { my $x = $_; $x =~ s/..*//; $x } @long_names; perlre
  175. 175. New Regex Modifiersmy @short_names = map { s/..*//r } @long_names; perlre
  176. 176. New Regex Modifiersmy @short_names = map s/..*//r, @long_names; perlre
  177. 177. New Regex Modifiers perldoc
  178. 178. New Regex Modifiers /u /a /aa /d /l"൮" =~ /d/ ✓ ! ! ¿? ¿?"ð" =~ /w/ ✓ ! ! ¿? ¿?"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿? perldoc
  179. 179. New Regex Modifiers /u /a /aa /d /l"൮" =~ /d/ ✓ ! ! ¿? ¿?"ð" =~ /w/ ✓ ! ! ¿? ¿?"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿? perldoc
  180. 180. New Regex Modifiers /u /a /aa /d /l"൮" =~ /d/ ✓ ! ! ¿? ¿?"ð" =~ /w/ ✓ ! ! ¿? ¿?"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿? perldoc
  181. 181. New Regex Modifiers /u /a /aa /d /l"൮" =~ /d/ ✓ ! ! ¿? ¿?"ð" =~ /w/ ✓ ! ! ¿? ¿?"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿? perldoc
  182. 182. New Regex Modifiers /u /a /aa /d /l"൮" =~ /d/ ✓ ! ! ¿? ¿?"ð" =~ /w/ ✓ ! ! ¿? ¿?"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿? perldoc
  183. 183. New Regex Modifiers /u /a /aa /d /l"൮" =~ /d/ ✓ ! ! ¿? ¿?"ð" =~ /w/ ✓ ! ! ¿? ¿?"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿? perldoc
  184. 184. New Regex Modifiers# To be really ASCII-only:die “funny un-American characters” if $str =~ /P{ASCII}/;$str =~ /...actual pattern.../; perlre
  185. 185. study
  186. 186. studymy $re = qr{...complex...};
  187. 187. studymy $re = qr{...complex...};my $str = q{...long complex...};
  188. 188. studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow!!
  189. 189. studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow!!study $str; # does stuff
  190. 190. studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow!!study $str; # does stuff$str =~ $re; # fast!!
  191. 191. studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow but right!!study $str; # does stuff$str =~ $re; # who knows!!
  192. 192. studymy $re = qr{...complex...};my $str = q{...long complex...};$str =~ $re; # slow but right!!study $str; # does nothing$str =~ $re; # slow but right!!
  193. 193. Modder Modlib
  194. 194. Newly Cored Librarys- JSON- HTTP::Tiny- Module::Metadata- CPAN::Meta perlmodlib
  195. 195. Newly Ejected Librarys- Devel::DProf- Switch- the perl4 core- ...and more perlmodlib
  196. 196. Old Stuff Removed
  197. 197. qw()for my $show qw(Smallville Lost V) { $tivo->cancel_pass( $show );} perlop
  198. 198. qw()for my $show (qw(Smallville Lost V)) { $tivo->cancel_pass( $show );} perlop
  199. 199. $[
  200. 200. $[ - first index of array perlvar
  201. 201. $[ - first index of array - so you can make $array[1] mean first perlvar
  202. 202. $[ - first index of array - so you can make $array[1] mean first - isn’t that awesome??? perlvar
  203. 203. $[ - first index of array - so you can make $array[1] mean first - isn’t that awesome??? - yeah, about as awesome as Comic Sans perlvar
  204. 204. $[$[ = 1;for (1 .. $#array) { ...} perlvar
  205. 205. $[for ($[ .. $#array) { ...} perlvar
  206. 206. $[Assigned to $[. Are you some kind ofidiot or something? at -e line 123. perlvar
  207. 207. $[Use of assignment to $[ is deprecatedat -e line 123. perlvar
  208. 208. defined @arr
  209. 209. Any questions?
  210. 210. Thank you!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×