Perl 5.12 for Everyday Use

2,008 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,008
On SlideShare
0
From Embeds
0
Number of Embeds
44
Actions
Shares
0
Downloads
40
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Perl 5.12 for Everyday Use

  1. 1. Perl 5.12 for everyday useSunday, December 5, 2010
  2. 2. 5.12 isn’t like 5.10 perl5100deltaSunday, December 5, 2010
  3. 3. 5.12 isn’t like 5.10 - after 5.8, we had to wait 5 years for 5.10 perl5100deltaSunday, December 5, 2010
  4. 4. 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 perl5100deltaSunday, December 5, 2010
  5. 5. 5.12 is a Nice Change perl5100deltaSunday, December 5, 2010
  6. 6. 5.12 is a Nice Change - 5.10 was a huge set of changes perl5100deltaSunday, December 5, 2010
  7. 7. 5.12 is a Nice Change - 5.10 was a huge set of changes - 5.12 is a lot smaller perl5100deltaSunday, December 5, 2010
  8. 8. 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 perl5100deltaSunday, December 5, 2010
  9. 9. 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 perl5100deltaSunday, December 5, 2010
  10. 10. 5.12 is a Mixed Bag perl5100deltaSunday, December 5, 2010
  11. 11. 5.12 is a Mixed Bag - this talk isn’t just for beginners perl5100deltaSunday, December 5, 2010
  12. 12. 5.12 is a Mixed Bag - this talk isn’t just for beginners - some of these changes are at the edges perl5100deltaSunday, December 5, 2010
  13. 13. 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 perl5100deltaSunday, December 5, 2010
  14. 14. 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 perl5100deltaSunday, December 5, 2010
  15. 15. By the way, 5.14... perl5132deltaSunday, December 5, 2010
  16. 16. By the way, 5.14... - is going to be awesome perl5132deltaSunday, December 5, 2010
  17. 17. By the way, 5.14... - is going to be awesome - and available in about nine months perl5132deltaSunday, December 5, 2010
  18. 18. By the way, 5.14... - is going to be awesome - and available in about nine months - and it’s going to be awesome perl5132deltaSunday, December 5, 2010
  19. 19. ...and 5.10 is frozen. perl5101deltaSunday, December 5, 2010
  20. 20. ...and 5.10 is frozen. - 5.10 is the last release of the old way perl5101deltaSunday, December 5, 2010
  21. 21. ...and 5.10 is frozen. - 5.10 is the last release of the old way - that means it got some features backported perl5101deltaSunday, December 5, 2010
  22. 22. ...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 perl5101deltaSunday, December 5, 2010
  23. 23. ...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 perl5101deltaSunday, December 5, 2010
  24. 24. but enough about other versionsSunday, December 5, 2010
  25. 25. let’s talk about 5.12Sunday, December 5, 2010
  26. 26. First: A Warning featureSunday, December 5, 2010
  27. 27. First: A Warning - 5.12 is backwards compatible featureSunday, December 5, 2010
  28. 28. First: A Warning - 5.12 is backwards compatible - but adds new keywords and operators featureSunday, December 5, 2010
  29. 29. First: A Warning - 5.12 is backwards compatible - but adds new keywords and operators - they’re not enabled by default featureSunday, December 5, 2010
  30. 30. First: A Warning - 5.12 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; featureSunday, December 5, 2010
  31. 31. 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; featureSunday, December 5, 2010
  32. 32. 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 featureSunday, December 5, 2010
  33. 33. 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! featureSunday, December 5, 2010
  34. 34. 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 featureSunday, December 5, 2010
  35. 35. $old ~~ $new - the smart match operator changed also in 5.10.1 perlsynSunday, December 5, 2010
  36. 36. ~~ - 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 perldocSunday, December 5, 2010
  37. 37. autodie also in 5.10.1 autodieSunday, December 5, 2010
  38. 38. autodie - like Fatal also in 5.10.1 autodieSunday, December 5, 2010
  39. 39. autodie - like Fatal - but deadlier also in 5.10.1 autodieSunday, December 5, 2010
  40. 40. autodie open my $fh, ‘>‘, $filename; while (<$fh>) { ... } close $fh; autodieSunday, December 5, 2010
  41. 41. autodie open my $fh, ‘>‘, $filename or die “couldn’t open $filename: $!”; while (<$fh>) { ... } close $fh or die “couldn’t close $filename: $!”; autodieSunday, December 5, 2010
  42. 42. autodie use autodie; open my $fh, ‘<‘, $filename; while (<$fh>) { ... } close $fh; autodieSunday, December 5, 2010
  43. 43. autodie use autodie; open my $fh, ‘>‘, $filename; while (<$fh>) { no autodie; rmdir or warn “couldn’t remove $_: $!”; } close $fh; autodieSunday, December 5, 2010
  44. 44. autodie problems - autodie doesn’t affect print - you must close filehandles explicitly perldocSunday, December 5, 2010
  45. 45. UnicodeSunday, December 5, 2010
  46. 46. Perl is Good at Unicode perlunicodeSunday, December 5, 2010
  47. 47. Perl 5.12 is Better perlunicodeSunday, December 5, 2010
  48. 48. Perl 5.12 is Better - Unicode 5.2 perlunicodeSunday, December 5, 2010
  49. 49. Perl 5.12 is Better - Unicode 5.2 - every character property is available perlunicodeSunday, December 5, 2010
  50. 50. Perl 5.12 is Better - Unicode 5.2 - every character property is available - X in regex is more sensible perlunicodeSunday, December 5, 2010
  51. 51. “The Unicode Bug” perlunicodeSunday, December 5, 2010
  52. 52. “The Unicode Bug” - strings aren’t always treated as Unicode perlunicodeSunday, December 5, 2010
  53. 53. “The Unicode Bug” - strings aren’t always treated as Unicode - this causes weird bugs that take ages to find perlunicodeSunday, December 5, 2010
  54. 54. “The Unicode Bug” - strings aren’t always treated as Unicode - this causes weird bugs that take ages to find - use feature ‘unicode_strings’; perlunicodeSunday, December 5, 2010
  55. 55. use feature ‘unicode_strings’; perldocSunday, December 5, 2010
  56. 56. use 5.12.0; perldocSunday, December 5, 2010
  57. 57. use 5.10.0; perldocSunday, December 5, 2010
  58. 58. use 5.10.0; use feature qw( say state switch ); perldocSunday, December 5, 2010
  59. 59. use 5.12.0; perldocSunday, December 5, 2010
  60. 60. use 5.12.0; use feature qw( say state switch unicode_strings ); perldocSunday, December 5, 2010
  61. 61. use 5.12.0; use feature qw( say state switch unicode_strings ); use strict; perldocSunday, December 5, 2010
  62. 62. Container ImprovementsSunday, December 5, 2010
  63. 63. my %hash = (a => 1, b => 2); while (my ($k, $v) = each %hash) { say “value for $k is $v”; }Sunday, December 5, 2010
  64. 64. 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 2Sunday, December 5, 2010
  65. 65. Sunday, December 5, 2010
  66. 66. my @array = qw(a b);Sunday, December 5, 2010
  67. 67. my @array = qw(a b); value for 0 is b value for 1 is aSunday, December 5, 2010
  68. 68. 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 aSunday, December 5, 2010
  69. 69. 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 aSunday, December 5, 2010
  70. 70. my @array = qw(a b); for my $k (0 .. $#array) { say “value for $k is $array[$k]”; } my @array = qw(a b); while (my ($k, $v) = each @array) { say “value for $k is $v”; }Sunday, December 5, 2010
  71. 71. 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); }Sunday, December 5, 2010
  72. 72. my @array = qw(a b); while (my ($k, $v) = each @array) { say “value for $k is $v”; }Sunday, December 5, 2010
  73. 73. my @array = qw(a b); while (my ($k, $v) = each @array) { say “value for $k is $v”; do_something(@array); }Sunday, December 5, 2010
  74. 74. my @array = qw(a b); while (my ($k, $v) = each @array) { say “value for $k is $v”; }Sunday, December 5, 2010
  75. 75. 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; } }Sunday, December 5, 2010
  76. 76. AVOID each @arraySunday, December 5, 2010
  77. 77. local ??Sunday, December 5, 2010
  78. 78. use Ancient::Utility qw(stuff); my $result = do { local $Ancient::Utility::WIDTH = 10; stuff( $input ); };Sunday, December 5, 2010
  79. 79. my $href = { a => 1, b => 2 }; my $result = do { local $href->{a} = 3; stuff( $href ); };Sunday, December 5, 2010
  80. 80. my $href = { a => 1, b => 2 }; my $result = do { delete local $href->{a}; stuff( $href ); };Sunday, December 5, 2010
  81. 81. $]Sunday, December 5, 2010
  82. 82. $[Sunday, December 5, 2010
  83. 83. $[ - first index of array perlvarSunday, December 5, 2010
  84. 84. $[ - first index of array - so you can make $array[1] mean first perlvarSunday, December 5, 2010
  85. 85. $[ - first index of array - so you can make $array[1] mean first - isn’t that awesome??? perlvarSunday, December 5, 2010
  86. 86. $[ - first index of array - so you can make $array[1] mean first - isn’t that awesome??? - yeah, about as awesome as Comic Sans perlvarSunday, December 5, 2010
  87. 87. $[ $[ = 1; for (1 .. $#array) { ... } perlvarSunday, December 5, 2010
  88. 88. $[ for ($[ .. $#array) { ... } perlvarSunday, December 5, 2010
  89. 89. $[ Assigned to $[. Are you some kind of idiot or something? at -e line 123. perlvarSunday, December 5, 2010
  90. 90. $[ Use of assignment to $[ is deprecated at -e line 123. perlvarSunday, December 5, 2010
  91. 91. More About DeprecationsSunday, December 5, 2010
  92. 92. @INCSunday, December 5, 2010
  93. 93. @INC: /usr/pkg/lib/perl5/5.8.0/i386-solaris /usr/pkg/lib/perl5/5.8.0 /usr/pkg/lib/perl5/site_perl/5.8.0/i386-solaris /usr/pkg/lib/perl5/site_perl/5.8.0 /usr/pkg/lib/perl5/site_perl /usr/pkg/lib/perl5/vendor_perl/5.8.0/i386-solaris /usr/pkg/lib/perl5/vendor_perl/5.8.0 /usr/pkg/lib/perl5/vendor_perl perlvarSunday, December 5, 2010
  94. 94. @INC: /usr/pkg/lib/perl5/5.8.0/i386-solaris /usr/pkg/lib/perl5/5.8.0 /usr/pkg/lib/perl5/site_perl/5.8.0/i386-solaris /usr/pkg/lib/perl5/site_perl/5.8.0 /usr/pkg/lib/perl5/site_perl /usr/pkg/lib/perl5/vendor_perl/5.8.0/i386-solaris /usr/pkg/lib/perl5/vendor_perl/5.8.0 /usr/pkg/lib/perl5/vendor_perl perlvarSunday, December 5, 2010
  95. 95. @INC: /usr/pkg/lib/perl5/site_perl/5.8.0/i386-solaris /usr/pkg/lib/perl5/site_perl/5.8.0 /usr/pkg/lib/perl5/site_perl /usr/pkg/lib/perl5/vendor_perl/5.8.0/i386-solaris /usr/pkg/lib/perl5/vendor_perl/5.8.0 /usr/pkg/lib/perl5/vendor_perl /usr/pkg/lib/perl5/5.8.0/i386-solaris /usr/pkg/lib/perl5/5.8.0 perlvarSunday, December 5, 2010
  96. 96. now we can remove stuff from the core distributionSunday, December 5, 2010
  97. 97. Class::ISA Pod::Plainer ShellSunday, December 5, 2010
  98. 98. Class::ISA Pod::Plainer Shell SwitchSunday, December 5, 2010
  99. 99. … and …Sunday, December 5, 2010
  100. 100. Sunday, December 5, 2010
  101. 101. my $x = get_input;Sunday, December 5, 2010
  102. 102. my $x = get_input; if ( $x >= 0 ) {Sunday, December 5, 2010
  103. 103. my $x = get_input; if ( $x >= 0 ) { do_something for 0 .. $x;Sunday, December 5, 2010
  104. 104. my $x = get_input; if ( $x >= 0 ) { do_something for 0 .. $x; } else {Sunday, December 5, 2010
  105. 105. my $x = get_input; if ( $x >= 0 ) { do_something for 0 .. $x; } else { ...Sunday, December 5, 2010
  106. 106. my $x = get_input; if ( $x >= 0 ) { do_something for 0 .. $x; } else { ... }Sunday, December 5, 2010
  107. 107. my $x = get_input; if ( $x >= 0 ) { do_something for 0 .. $x; } else { ... }Sunday, December 5, 2010
  108. 108. my $x = get_input; if ( $x >= 0 ) { do_something for 0 .. $x; } else { die “Unimplemented” }Sunday, December 5, 2010
  109. 109. sub virtual_method { ... }Sunday, December 5, 2010
  110. 110. sub method_I_will_write_later { ... }Sunday, December 5, 2010
  111. 111. Unimplemented at Some::Library line 123Sunday, December 5, 2010
  112. 112. AVOID ...Sunday, December 5, 2010
  113. 113. AVOID ... (except maybe in slides and pseudocode)Sunday, December 5, 2010
  114. 114. sub virtual_method { confess ‘...’ } sub method_I_will_write_later { confess ‘...’ }Sunday, December 5, 2010
  115. 115. error message improvementsSunday, December 5, 2010
  116. 116. perldiagSunday, December 5, 2010
  117. 117. perldiagSunday, December 5, 2010
  118. 118. perldiagSunday, December 5, 2010
  119. 119. perl -MCGI -e’my $q = CGI->new;’ Unrecognized character xE2 in column 12 at -e line 1. perldiagSunday, December 5, 2010
  120. 120. perl -MCGI -e’my $q = CGI->new;’ Unrecognized character xE2 in column 12 at -e line 1. 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. perldiagSunday, December 5, 2010
  121. 121. My Favorite 5.10-ism? $str = “Greetings, $name. Your last login was $last. It is now $time.”; Use of uninitialized value $time in concatenation (.) or string at hello.plx line 9. perldiagSunday, December 5, 2010
  122. 122. My Favorite 5.12-ism? if (length $input->{new_email}) { $user->update_email(...); } perldiagSunday, December 5, 2010
  123. 123. My Favorite 5.12-ism? if (length $input->{new_email}) { $user->update_email(...); } Use of uninitialized value in length at - line 3120. perldiagSunday, December 5, 2010
  124. 124. My Favorite 5.12-ism? if (length $input->{new_email}) { $user->update_email(...); } perldiagSunday, December 5, 2010
  125. 125. overloadingSunday, December 5, 2010
  126. 126. my $object = Object->new; print $object;Sunday, December 5, 2010
  127. 127. my $object = Object->new; { no overloading; print $object; }Sunday, December 5, 2010
  128. 128. my $filename = get_filename; if (-d $filename) { handle_directory($filename); }Sunday, December 5, 2010
  129. 129. 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’; ...; };Sunday, December 5, 2010
  130. 130. my $file = get_file; if (-d $file) { handle_directory($file); }Sunday, December 5, 2010
  131. 131. my $filename = get_file; if (-d $file and -x _) { handle_directory($file); }Sunday, December 5, 2010
  132. 132. my $filename = get_filename; if (-d -x $filename) { handle_directory($filename); }Sunday, December 5, 2010
  133. 133. AVOID overload -XSunday, December 5, 2010
  134. 134. y2038Sunday, December 5, 2010
  135. 135. Sunday, December 5, 2010
  136. 136. ~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Sunday, December 5, 2010
  137. 137. ~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’ Mon Jan 18 22:14:07 2038Sunday, December 5, 2010
  138. 138. ~$ 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’Sunday, December 5, 2010
  139. 139. ~$ 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 1901Sunday, December 5, 2010
  140. 140. Sunday, December 5, 2010
  141. 141. ~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Sunday, December 5, 2010
  142. 142. ~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’ Mon Jan 18 22:14:07 2038Sunday, December 5, 2010
  143. 143. ~$ 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’Sunday, December 5, 2010
  144. 144. ~$ 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 2038Sunday, December 5, 2010
  145. 145. some non-everyday changesSunday, December 5, 2010
  146. 146. Method Resolution Order A B C D mroSunday, December 5, 2010
  147. 147. Method Resolution Order A - 5.8 : D, B, A, C B C D mroSunday, December 5, 2010
  148. 148. Method Resolution Order A - 5.8 : D, B, A, C - 5.10: D, B, C, A B C D mroSunday, December 5, 2010
  149. 149. Method Resolution Order A - 5.8 : D, B, A, C - 5.10: D, B, C, A B C - 5.12: Anything! D mroSunday, December 5, 2010
  150. 150. Method Resolution Order A - 5.8 : D, B, A, C - 5.10: D, B, C, A B C - 5.12: F D MRO::DefineSunday, December 5, 2010
  151. 151. use strict; use warnings; package Booster::Gold; our $VERSION = ‘1.00’; ... 1;Sunday, December 5, 2010
  152. 152. use 5.12.0; use warnings; package Booster::Gold 1.00; ... 1;Sunday, December 5, 2010
  153. 153. use 5.14.0; use warnings; package Booster::Gold 1.00 { ... } 1;Sunday, December 5, 2010
  154. 154. http://www.perl.org/get.htmlSunday, December 5, 2010
  155. 155. Any questions?Sunday, December 5, 2010

×