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

Perl 5: Postcards from the Edge

Perl 5: Postcards from the Edge

Cec6b9b88295ead26c65f8747a76561b?s=128

Ricardo Signes

June 05, 2013
Tweet

More Decks by Ricardo Signes

Other Decks in Programming

Transcript

  1. Perl 5.18 who cares?

  2. Perl 5 postcards from the edge

  3. None
  4. None
  5. …perl was a mess…

  6. …but these days…

  7. …perl is a mess.

  8. None
  9. We love our perl.

  10. We love our perl. It is a mess.

  11. We love our perl. It is a mess. Nobody is

    going to change that.
  12. We love our perl. It is a mess. Nobody is

    going to change that. So don't worry.
  13. None
  14. What is new?

  15. What is new? Why is it new?

  16. What is new? Why is it new? What will be

    new next?
  17. What is new? Why is it new? What will be

    new next? What won't?
  18. What is new? Why is it new? What will be

    new next? What won't? Why?
  19. Perl 5.18 who cares?

  20. - Renaming packages through glob assignment ("*Foo:: = *Bar::; *Bar::

    = *Baz::") in combination with "m?...?" and "reset" no longer makes threaded builds crash.
  21. - If the hint hash %^H is tied...

  22. Regex Character Sets

  23. Regex Sets

  24. Regex Sets - regex have character sets:

  25. Regex Sets - regex have character sets: - $a =~

    /[a-z]/
  26. Regex Sets - regex have character sets: - $a =~

    /[a-z]/ - but you can't do set operations
  27. Regex Sets - regex have character sets: - $a =~

    /[a-z]/ - but you can't do set operations - …except for addition
  28. Regex Sets

  29. $a =~ /[a-z]/ Regex Sets

  30. $a =~ /[a-z]/ $a =~ /[a-z0-9]/ Regex Sets

  31. $a =~ /[a-z]/ $a =~ /[a-z0-9]/ $a =~ /[a-z0-9](?<!3)/ Regex

    Sets
  32. Regex Sets

  33. $a =~ /(?[ Regex Sets

  34. $a =~ /(?[ ( \pL Regex Sets

  35. $a =~ /(?[ ( \pL + \pN Regex Sets

  36. $a =~ /(?[ ( \pL + \pN - \p{Numeric_Value=3} Regex

    Sets
  37. $a =~ /(?[ ( \pL + \pN - \p{Numeric_Value=3} )

    Regex Sets
  38. $a =~ /(?[ ( \pL + \pN - \p{Numeric_Value=3} )

    & ( ! \p{Script=Cyrillic}) Regex Sets
  39. $a =~ /(?[ ( \pL + \pN - \p{Numeric_Value=3} )

    & ( ! \p{Script=Cyrillic}) ])/ Regex Sets
  40. no warnings 'experimental::regex_sets'; $a =~ /(?[ ( \pL + \pN

    - \p{Numeric_Value=3} ) & ( ! \p{Script=Cyrillic}) ])/ Regex Sets
  41. Lexical Subroutines

  42. None
  43. sub sum {

  44. sub sum { my $x = shift;

  45. sub sum { my $x = shift; my sub adder

    {
  46. sub sum { my $x = shift; my sub adder

    { my ($y) = shift;
  47. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y
  48. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y }
  49. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ );
  50. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); }
  51. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2);
  52. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3);
  53. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4);
  54. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3
  55. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 # 5
  56. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 # 5 # 7
  57. sub sum { my $x = shift; state sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4);
  58. sub sum { my $x = shift; state sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 !?
  59. sub sum { my $x = shift; state sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 !? # 4 !?
  60. sub sum { my $x = shift; state sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); } sum(1,2); sum(2,3); sum(3,4); # 3 !? # 4 !? # 5 !?
  61. None
  62. # ...some test file...

  63. # ...some test file... sub diag {

  64. # ...some test file... sub diag { say $_[0];

  65. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

  66. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    }
  67. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester {
  68. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz {
  69. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”);
  70. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); }
  71. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } }
  72. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper {
  73. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines {
  74. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”);
  75. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”); }
  76. # ...some test file... sub diag { say $_[0]; emit_diagnostics;

    } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”); } }
  77. # ...some test file... my sub diag { say $_[0];

    emit_diagnostics; } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”); } }
  78. Some bad thing happened at file.p5 line 12. main::emit_diagnostics(...) called

    at file.p5 line 10 (unknown)(3, 4) called at file.p5 line 9 Tester::test_xyz() called at file.p5 line 15
  79. # ...some test file... our sub diag { say $_[0];

    emit_diagnostics; } package Tester { sub test_xyz { ...; diag(“Just tested xyz!”); } } package Helper { sub reticulate_splines { ...; diag(“Reticulated!”); } }
  80. sub sum { my $x = shift; my sub adder

    { my ($y) = shift; $x + $y } adder( @_ ); }
  81. None
  82. use feature 'lexical_subs';

  83. use feature 'lexical_subs'; sub sum {

  84. use feature 'lexical_subs'; sub sum { my $x = shift;

  85. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder {
  86. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder { my ($y) = shift;
  87. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder { my ($y) = shift; $x + $y
  88. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder { my ($y) = shift; $x + $y }
  89. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder { my ($y) = shift; $x + $y } adder( @_ );
  90. use feature 'lexical_subs'; sub sum { my $x = shift;

    my sub adder { my ($y) = shift; $x + $y } adder( @_ ); }
  91. None
  92. use feature 'lexical_subs';

  93. use feature 'lexical_subs'; no warnings

  94. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';

  95. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum {

  96. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift;
  97. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift; my sub adder {
  98. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift; my sub adder { my ($y) = shift;
  99. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift; my sub adder { my ($y) = shift; $x + $y
  100. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift; my sub adder { my ($y) = shift; $x + $y }
  101. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift; my sub adder { my ($y) = shift; $x + $y } adder( @_ );
  102. use feature 'lexical_subs'; no warnings 'experimental::lexical_subs'; sub sum { my

    $x = shift; my sub adder { my ($y) = shift; $x + $y } adder( @_ ); }
  103. Experimental Features

  104. Lexical Topic

  105. None
  106. sub print_next {

  107. sub print_next { local $_ = shift;

  108. sub print_next { local $_ = shift; chomp;

  109. sub print_next { local $_ = shift; chomp; s/^\s+//;

  110. sub print_next { local $_ = shift; chomp; s/^\s+//; reset_stdout;

  111. sub print_next { local $_ = shift; chomp; s/^\s+//; reset_stdout;

    print;
  112. sub print_next { local $_ = shift; chomp; s/^\s+//; reset_stdout;

    print; }
  113. sub print_next { my $_ = shift; chomp; s/^\s+//; reset_stdout;

    print; }
  114. sub print_next { my $_ = shift; chomp; s/^\s+//; reset_stdout;

    print; }
  115. sub print_next { my $_ = shift; chomp; s/^\s+//; reset_stdout;

    print; } sub reset_stdout { ... }
  116. sub print_next { my $_ = shift; chomp; s/^\s+//; reset_stdout;

    print; } sub reset_stdout { ... } sub reset_stdout(_) { ... }
  117. None
  118. sub reset_stdout { prep_for( length ); }

  119. sub reset_stdout { prep_for( length ); } sub reset_stdout (_)

    { prep_for( length ); }
  120. use Try::Tiny; try { die "ignore"; } catch { die

    $_ unless /ignore/; }
  121. use Try::Tiny; my $_ = "ho ho ho"; try {

    die "ignore"; } catch { die $_ unless /ignore/; }
  122. use Try::Tiny; my $_ = "ho ho ho"; try {

    die "ignore"; } catch sub (_) { die $_[0] unless $_[0] =~ /ignore/; }
  123. use Try::Tiny; my $_ = "ho ho ho"; try {

    die "ignore"; } catch { die $::_ unless $::_ =~ /ignore/; }
  124. Smrt Match

  125. Let's Not… …and say we did.

  126. None
  127. $a $b Meaning ======= ======= =============== Any undef ! defined

    $a Any ~~-overloaded ~~ overloading Any Regexp, qr-ol $a =~ $b Any CodeRef, &{}-ol $b->($a) Any Any fatal
  128. $a $b Meaning ======= ======= =============== Any undef ! defined

    $a Any ~~-overloaded ~~ overloading Any Regexp, qr-ol $a =~ $b Any CodeRef, &{}-ol $b->($a) Any Any fatal given ($x) { when ($y) { ... } # $x ~~ $y when (4) { ... } # $x == 4 when (‘4’) { ... } # $x eq 4 }
  129. given ($x) { when ($y) { ... ... } }

  130. None
  131. use Try::Tiny;

  132. use Try::Tiny; given ($x) {

  133. use Try::Tiny; given ($x) { when ($y) {

  134. use Try::Tiny; given ($x) { when ($y) { try {

    ... }
  135. use Try::Tiny; given ($x) { when ($y) { try {

    ... } catch { die if /fatal/ };
  136. use Try::Tiny; given ($x) { when ($y) { try {

    ... } catch { die if /fatal/ }; }
  137. use Try::Tiny; given ($x) { when ($y) { try {

    ... } catch { die if /fatal/ }; } }
  138. Hash Randomization

  139. "Common" Knowledge

  140. ~$ perl -E <<END "Common" Knowledge

  141. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); "Common" Knowledge
  142. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; "Common" Knowledge
  143. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; say %h1; say %h2 "Common" Knowledge
  144. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; say %h1; say %h2 END "Common" Knowledge
  145. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; say %h1; say %h2 END 1234 "Common" Knowledge
  146. ~$ perl -E <<END %h1 = (1 => 2, 3

    => 4); %h2 = %h1; say %h1; say %h2 END 1234 1234 "Common" Knowledge
  147. "Common" Knowledge

  148. ~$ perl -E <<END "Common" Knowledge

  149. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); "Common" Knowledge
  150. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; "Common" Knowledge
  151. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 "Common" Knowledge
  152. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END "Common" Knowledge
  153. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END 334112 "Common" Knowledge
  154. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END 334112 112334 "Common" Knowledge
  155. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END 334112 "Common" Knowledge
  156. ~$ perl -E <<END %h1 = (11 => 2, 33

    => 4); %h2 = %h1; say %h1; say %h2 END 334112 112334 "Common" Knowledge
  157. Just Remember… - keys %hash and values %hash are in

    the same order as each other - they both change if you alter the hash - so does each and list order
  158. (?{…}) and (??{…})

  159. split

  160. None
  161. $x = "␠␠␠x␠␠y␠␠␠␠z";

  162. $x = "␠␠␠x␠␠y␠␠␠␠z"; split '␠', $x; # (x, y, z)

  163. $x = "␠␠␠x␠␠y␠␠␠␠z"; split '␠', $x; # (x, y, z)

    $y = '␠';
  164. $x = "␠␠␠x␠␠y␠␠␠␠z"; split '␠', $x; # (x, y, z)

    $y = '␠'; split $y, $x; # ('␠') x 3,
  165. $x = "␠␠␠x␠␠y␠␠␠␠z"; split '␠', $x; # (x, y, z)

    $y = '␠'; split $y, $x; # ('␠') x 3, # x, '␠', y
  166. $x = "␠␠␠x␠␠y␠␠␠␠z"; split '␠', $x; # (x, y, z)

    $y = '␠'; split $y, $x; # ('␠') x 3, # x, '␠', y # ('␠') x 3,
  167. $x = "␠␠␠x␠␠y␠␠␠␠z"; split '␠', $x; # (x, y, z)

    $y = '␠'; split $y, $x; # ('␠') x 3, # x, '␠', y # ('␠') x 3, # z
  168. Fond Farewells

  169. Fond Farewells - File::CheckTree - Text::SoundEx - Pod::LaTeX - CPANPLUS

  170. Perl5

  171. 7 7 Perl

  172. Perl5

  173. Perl5S

  174. Perl 5s

  175. None
  176. None
  177. None
  178. None
  179. None
  180. None
  181. Why I ♥ Turban Squash

  182. Why I ♥ Turban Squash - it's like an experimental

    feature
  183. Why I ♥ Turban Squash - it's like an experimental

    feature - you start with perl
  184. Why I ♥ Turban Squash - it's like an experimental

    feature - you start with perl - then break it
  185. Why I ♥ Turban Squash - it's like an experimental

    feature - you start with perl - then break it - see how much you broke, how much you win
  186. Why I ♥ Turban Squash - it's like an experimental

    feature - you start with perl - then break it - see how much you broke, how much you win - and then I can steal your work from you
  187. Perl5

  188. Perl5

  189. Τί ἐστιν Περλ;

  190. Τί ἐστιν Περλ; - "Perl should get more Perlish."

  191. Τί ἐστιν Περλ; - "Perl should get more Perlish." -

    What?
  192. Τί ἐστιν Περλ; - "Perl should get more Perlish." -

    What? - Perl is a whole made of parts that work together nicely.
  193. Τί ἐστιν Περλ; - "Perl should get more Perlish." -

    What? - Perl is a whole made of parts that work together nicely. - (pause for laughter)
  194. Τί ἐστιν Περλ; - teachable - guessable - extensible -

    compatible
  195. None
  196. OH SNAP

  197. None
  198. BACKCOMPAT

  199. Backcompat Killed My Dog - "We should break horrible old

    features to allow evolution." - "We don't make change because of backcompat."
  200. Success hates agility.

  201. - "We all agree on the necessity of compromise. We

    just can't agree on when it's necessary to compromise." — Larry Backcompat Killed My Dog
  202. - "We all agree on [removing cruft]. We just can't

    agree on [what cruft] to [remove]." — [Larry] Backcompat Killed My Dog
  203. Backcompat has prevented very, very few real patches from landing.

  204. How many patches have not been written because of backcompat

    concerns?
  205. How many patches have been "discussed" until they don't happen?

  206. Some

  207. Talked To Death

  208. Talked To Death - maybe we figure out that it

    was a bad idea
  209. Talked To Death - maybe we figure out that it

    was a bad idea - maybe the perfect is the enemy of the good
  210. Talked To Death - maybe we figure out that it

    was a bad idea - maybe the perfect is the enemy of the good - maybe nobody's willing to decide the debate
  211. None
  212. <Phaedo> how to deprecate: step 1. have a huge flame-war

    on p5p mailing list
  213. <Phaedo> how to deprecate: step 1. have a huge flame-war

    on p5p mailing list <Alcibiades> step 2. after no conclusive result on the mailing list, deprecate anyway
  214. - "We all agree on the necessity of compromise. We

    just can't agree on when it's necessary to compromise." — Larry Talked to Death
  215. - "We all agree on the necessity of compromise. [Ricardo

    can] agree on when it's necessary to compromise." — [Ricardo] Talked to Death
  216. Perl Needs Hackers

  217. Daddy, where do patches come from?

  218. None
  219. - most of our patches come from four people -

    Perl is not dead - but perl5.git is on life support - but: everybody in this room is a doctor
  220. None
  221. - If you want a feature…

  222. - If you want a feature… - …write it!

  223. - If you want a feature… - …write it! -

    If you don't know how…
  224. - If you want a feature… - …write it! -

    If you don't know how… - ask for help.
  225. - If you want a feature… - …write it! -

    If you don't know how… - ask for help. - If you don't want to write it…
  226. - If you want a feature… - …write it! -

    If you don't know how… - ask for help. - If you don't want to write it… - discuss with p5p how it might help.
  227. Perl Hackers Need Code Review

  228. None
  229. None
  230. My Hopes and Dreams

  231. fatal implicit close()

  232. fatal implicit close()

  233. { fatal implicit close()

  234. { use autodie; fatal implicit close()

  235. { use autodie; open my $fh, ‘>’, $filename; fatal implicit

    close()
  236. { use autodie; open my $fh, ‘>’, $filename; $fh->print( ...

    ); fatal implicit close()
  237. { use autodie; open my $fh, ‘>’, $filename; $fh->print( ...

    ); } # should die if close fails! fatal implicit close()
  238. postfix dereferencing

  239. None
  240. push @{ $x->{foo}->[0]->m }, $y;

  241. push @{ $x->{foo}->[0]->m }, $y; push $x->{foo}->[0]->m , $y;

  242. push @{ $x->{foo}->[0]->m }, $y; push $x->{foo}->[0]->m , $y; push

    $x->{foo}->[0]->m->@*, $y;
  243. push @{ $x->{foo}->[0]->m }, $y; push $x->{foo}->[0]->m , $y; push

    $x->{foo}->[0]->m->@*, $y; push @y, @{ $x->{foo}->[0]->m };
  244. push @{ $x->{foo}->[0]->m }, $y; push $x->{foo}->[0]->m , $y; push

    $x->{foo}->[0]->m->@*, $y; push @y, @{ $x->{foo}->[0]->m }; push @y, $x->{foo}->[0]->m->@*;
  245. None
  246. print ${ $x->body_ref };

  247. print ${ $x->body_ref }; print $x->body_ref->$*;

  248. print ${ $x->body_ref }; print $x->body_ref->$*; $x = \*Package::ISA;

  249. print ${ $x->body_ref }; print $x->body_ref->$*; $x = \*Package::ISA; $x->**->@*;

    # ...maybe not...
  250. better exceptions

  251. my $x = try { $y / $z } catch

    { return $Infinity if $_->tagged(‘divbyzero’); die $_; } better exceptions
  252. better types

  253. chars v. bytes

  254. my $buf = $fh->readline; chars v. bytes

  255. my $buf = $fh->readline; my $str = decode_utf8($buf); chars v.

    bytes
  256. my $buf = $fh->readline; my $str = decode_utf8($buf); STDOUT->print( $str

    ); chars v. bytes
  257. my $buf = $fh->readline; my $str = decode_utf8($buf); STDOUT->print( $str

    ); # fatal unless encoding layer chars v. bytes
  258. autoboxing

  259. autoboxing

  260. @array->push(@list); autoboxing

  261. @array->push(@list); $arrayref->push(@list); autoboxing

  262. @array->push(@list); $arrayref->push(@list); for ($x->values) { ... } autoboxing

  263. magic MRO

  264. Any questions?

  265. Thank you!