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

Perl 5.12 for Everyday Use

Perl 5.12 for Everyday Use

Perl 5.12 is here! It brings a number of cool new features that everyone can use as well as a lot of internal improvements that only five people on the planet understand. This talk only focuses on the first, so that you can skip reading the detailed release notes and just start using the cool stuff seen here.

Ricardo Signes

June 23, 2010
Tweet

More Decks by Ricardo Signes

Other Decks in Programming

Transcript

  1. perl5100delta 5.12 isn’t like 5.10 - after 5.8, we had

    to wait 5 years for 5.10 - 5.12 came out 2 years after 5.10
  2. perl5100delta 5.12 is a Nice Change - 5.10 was a

    huge set of changes - 5.12 is a lot smaller
  3. perl5100delta 5.12 is a Nice Change - 5.10 was a

    huge set of changes - 5.12 is a lot smaller - 5.12 is not as compelling as 5.10
  4. perl5100delta 5.12 is a Nice Change - 5.10 was a

    huge set of changes - 5.12 is a lot smaller - 5.12 is not as compelling as 5.10 - and that’s a good thing
  5. perl5100delta 5.12 is a Mixed Bag - this talk isn’t

    just for beginners - some of these changes are at the edges
  6. perl5100delta 5.12 is a Mixed Bag - this talk isn’t

    just for beginners - some of these changes are at the edges - but they’re all practical
  7. perl5100delta 5.12 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
  8. perl5132delta By the way, 5.14... - is going to be

    awesome - and available in about nine months
  9. perl5132delta By the way, 5.14... - is going to be

    awesome - and available in about nine months - and it’s going to be awesome
  10. perl5101delta ...and 5.10 is frozen. - 5.10 is the last

    release of the old way - that means it got some features backported
  11. perl5101delta ...and 5.10 is frozen. - 5.10 is the last

    release of the old way - that means it got some features backported - that will never happen again
  12. perl5101delta ...and 5.10 is frozen. - 5.10 is the last

    release of the old way - that means it got some features backported - that will never happen again - I’ll point out 5.12isms that got into 5.10.1
  13. feature First: A Warning - 5.12 is backwards compatible -

    but adds new keywords and operators
  14. feature First: A Warning - 5.12 is backwards compatible -

    but adds new keywords and operators - they’re not enabled by default
  15. feature First: A Warning - 5.12 is backwards compatible -

    but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’;
  16. feature First: A Warning - 5.12 is backwards compatible -

    but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.012;
  17. feature First: A Warning - 5.12 is backwards compatible -

    but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.012; - read the perldoc
  18. feature First: A Warning - 5.12 is backwards compatible -

    but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.012; - read the perldoc I’m a perldoc ref!
  19. feature First: A Warning - 5.12 is backwards compatible -

    but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.012; - read the perldoc
  20. perldoc ~~ - no longer commutative; right side wins -

    non-overloaded objects can’t be ~~ed - still very complicated (23 behaviors) - you won’t be using this every day
  21. autodie autodie open my $fh, ‘>‘, $filename or die “couldn’t

    open $filename: $!”; while (<$fh>) { ... } close $fh or die “couldn’t close $filename: $!”;
  22. autodie autodie use autodie; open my $fh, ‘>‘, $filename; while

    (<$fh>) { no autodie; rmdir or warn “couldn’t remove $_: $!”; } close $fh;
  23. perlunicode Perl 5.12 is Better - Unicode 5.2 - every

    character property is available - \X in regex is more sensible
  24. perlunicode “The Unicode Bug” - strings aren’t always treated as

    Unicode - this causes weird bugs that take ages to find
  25. perlunicode “The Unicode Bug” - strings aren’t always treated as

    Unicode - this causes weird bugs that take ages to find - use feature ‘unicode_strings’;
  26. my %hash = (a => 1, b => 2); while

    (my ($k, $v) = each %hash) { say “value for $k is $v”; }
  27. my %hash = (a => 1, b => 2); while

    (my ($k, $v) = each %hash) { say “value for $k is $v”; } value for a is 1 value for b is 2
  28. my @array = qw(a b); for my $k (0 ..

    $#array) { say “value for $k is $array[$k]”; } value for 0 is b value for 1 is a
  29. my @array = qw(a b); while (my ($k, $v) =

    each @array) { say “value for $k is $v”; } value for 0 is b value for 1 is a
  30. my @array = qw(a b); while (my ($k, $v) =

    each @array) { say “value for $k is $v”; } my @array = qw(a b); for my $k (0 .. $#array) { say “value for $k is $array[$k]”; }
  31. sub redump { my ($href) = @_; while (my ($k,

    $v) = each %hash) { say “value for $k is $v”; } } my %hash = (a => 1, b => 2); while (my ($k, $v) = each %hash) { print “== $k ==”; redump(\%hash); }
  32. my @array = qw(a b); while (my ($k, $v) =

    each @array) { say “value for $k is $v”; }
  33. my @array = qw(a b); while (my ($k, $v) =

    each @array) { say “value for $k is $v”; do_something(\@array); }
  34. my @array = qw(a b); while (my ($k, $v) =

    each @array) { say “value for $k is $v”; }
  35. my @array = qw(a b); while (my ($k, $v) =

    each @array) { my $string = $part_for_maybe_transient->bodyhandle->as_string; my $transient_pos = _match_position($string, $Not_An_Error); last unless defined $transient_pos; my $permanent_pos = _match_position($string, $Really_An_Error); my $orig_msg_pos = _match_position($string, $Returned_Message_Below); last if _position_before($permanent_pos, $orig_msg_pos); if (_position_before($transient_pos, $orig_msg_pos)) { say “value for $k is $v”; last if $message->effective_type eq ‘multipart/report’; last if !$first_part || $first_part->effective_type ne ‘text/plain’; my $string = $first_part->as_string; last if length($string) > 3000; # added return receipt (fix for bug #41870) last if $string !~ /auto.{0,20}reply|return receipt |vacation|(out|away|on holiday).*office/i; $self->log(“looks like an autoreply, ignoring.”); $self->{type} = “vacation autoreply”; $self->{is_bounce} = 0; return $self; } }
  36. my $href = { a => 1, b => 2

    }; my $result = do { local $href->{a} = 3; stuff( $href ); };
  37. my $href = { a => 1, b => 2

    }; my $result = do { delete local $href->{a}; stuff( $href ); };
  38. $]

  39. $[

  40. perlvar $[ - first index of array - so you

    can make $array[1] mean first
  41. perlvar $[ - first index of array - so you

    can make $array[1] mean first - isn’t that awesome???
  42. perlvar $[ - first index of array - so you

    can make $array[1] mean first - isn’t that awesome??? - yeah, about as awesome as Comic Sans
  43. perlvar $[ Assigned to $[. Are you some kind of

    idiot or something? at -e line 123.
  44. my $x = get_input; if ( $x >= 0 )

    { do_something for 0 .. $x;
  45. my $x = get_input; if ( $x >= 0 )

    { do_something for 0 .. $x; } else {
  46. my $x = get_input; if ( $x >= 0 )

    { do_something for 0 .. $x; } else { ...
  47. my $x = get_input; if ( $x >= 0 )

    { do_something for 0 .. $x; } else { ... }
  48. my $x = get_input; if ( $x >= 0 )

    { do_something for 0 .. $x; } else { ... }
  49. my $x = get_input; if ( $x >= 0 )

    { do_something for 0 .. $x; } else { die “Unimplemented” }
  50. perldiag perl -MCGI -e’my $q = CGI­−->new;’ Unrecognized character \xE2;

    marked by <-- HERE after y $q = CGI<-- HERE near column 12 at -e line 1. perl -MCGI -e’my $q = CGI->new;’ Unrecognized character \xE2 in column 12 at -e line 1.
  51. perldiag My Favorite 5.10-ism? Use of uninitialized value $time in

    concatenation (.) or string at hello.plx line 9. $str = “Greetings, $name. Your last login was $last. It is now $time.”;
  52. perldiag My Favorite 5.12-ism? Use of uninitialized value in length

    at - line 3120. if (length $input->{new_email}) { $user->update_email(...); }
  53. package Filename; use overload ‘-X’ => sub { my ($self,

    $test) = @_; return $self->is_dir if $test eq ‘d’; return $self->cd_able if $test eq ‘x’; ...; };
  54. ~$ 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’
  55. ~$ 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
  56. ~$ 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’
  57. ~$ 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
  58. A B C D Method Resolution Order - 5.8 :

    D, B, A, C - 5.10: D, B, C, A mro
  59. A B C D Method Resolution Order - 5.8 :

    D, B, A, C - 5.10: D, B, C, A - 5.12: Anything! mro
  60. A B C D Method Resolution Order - 5.8 :

    D, B, A, C - 5.10: D, B, C, A - 5.12: F MRO::Define