-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
878 lines (708 loc) · 13.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
<!DOCTYPE html>
<html>
<head>
<title>perldelta - What's Changed in Perl From v5.8 to v5.20</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script src="remark/remark.min.js" type="text/javascript">
{
"highlightStyle": "solarized_light",
"highlightLanguage": "no-highlight"
}
</script>
<style type="text/css" media="screen">
/*
SOLARIZED HEX 16/8 TERMCOL XTERM/HEX L*A*B RGB HSB
--------- ------- ---- ------- ----------- ---------- ----------- -----------
base03 #002b36 8/4 brblack 234 #1c1c1c 15 -12 -12 0 43 54 193 100 21
base02 #073642 0/4 black 235 #262626 20 -12 -12 7 54 66 192 90 26
base01 #586e75 10/7 brgreen 240 #585858 45 -07 -07 88 110 117 194 25 46
base00 #657b83 11/7 bryellow 241 #626262 50 -07 -07 101 123 131 195 23 51
base0 #839496 12/6 brblue 244 #808080 60 -06 -03 131 148 150 186 13 59
base1 #93a1a1 14/4 brcyan 245 #8a8a8a 65 -05 -02 147 161 161 180 9 63
base2 #eee8d5 7/7 white 254 #e4e4e4 92 -00 10 238 232 213 44 11 93
base3 #fdf6e3 15/7 brwhite 230 #ffffd7 97 00 10 253 246 227 44 10 99
yellow #b58900 3/3 yellow 136 #af8700 60 10 65 181 137 0 45 100 71
orange #cb4b16 9/3 brred 166 #d75f00 50 50 55 203 75 22 18 89 80
red #dc322f 1/1 red 160 #d70000 50 65 45 220 50 47 1 79 86
magenta #d33682 5/5 magenta 125 #af005f 50 65 -05 211 54 130 331 74 83
violet #6c71c4 13/5 brmagenta 61 #5f5faf 50 15 -45 108 113 196 237 45 77
blue #268bd2 4/4 blue 33 #0087ff 55 -10 -45 38 139 210 205 82 82
cyan #2aa198 6/6 cyan 37 #00afaf 60 -35 -05 42 161 152 175 74 63
green #859900 2/2 green 64 #5f8700 60 -20 65 133 153 0 68 100 60
*/
body {
font-size: 1.3em;
}
.slide .inverse {
color: #839496; /* base0 */
background-color: #002b36; /* base03 */
}
.slide {
color: #657b83; /* base00 */
background-color: #fdf6e3; /* base3 */
}
.slide pre, .slide code {
color: #586e75; /* base01 */
background-color: #eee8d5; /* base2 */
}
.slide .inverse pre, .slide .inverse code {
color: #93a1a1; /* base1 */
background-color: #073642; /* base02 */
}
a:link, a:visited, a:hover, a:active {
color: #268bd2; /* blue */
}
.footnote {
position: absolute;
bottom: 3em;
}
.footnote.right {
right: 3em;
}
.code {
font-family: Monaco, monospace;
}
.code-half {
float: left; width: 48%; margin: 1%;
}
h1, h2, h3 { text-align: center; }
h5, h6 { margin: 0.5em; font-weight: normal }
img { width: 100% }
</style>
</head>
<body>
<textarea id="source">
name: title
class: center, middle, inverse
# perldelta
## The Good Parts
### v5.8 - v5.20
.footnote.right[Chicago.PM]
---
class: center, middle
Perl 5.8 was released July 18, 2002
![Perl 5.8 was released July 18, 2002](images/perl-5.8-announcement.png)
Facebook was launched in 2004
---
class: center, middle
Perl 5.8.8 was released January 31, 2006
![Perl 5.8.8 was released January 31, 2006](images/perl-5.8.8-announcement.png)
Twitter was launched in July 2006
---
class: middle
# Perl Releases
* 5.10 - 2007-12-18
* 5.12 - 2010-04-12
* 5.14 - 2011-05-14
* 5.16 - 2012-05-20
* 5.18 - 2013-05-18
* 5.20 - 2014
---
class: middle
# OS Perl versions:
* Debian Squeeze (6.0 - 2011-02-06): 5.10.1
* Debian Wheezy (7.0 - 2013-05-04): 5.14.2
* Debian Jessie (8.0 - Developing): 5.18.2
* Ubuntu Lucid (10.04LTS - 2010-04): 5.10.1
* Ubuntu Precise (12.04LTS - 2012-04): 5.14.2
* Ubuntu Saucy (13.10 - 2013-10): 5.14.2
* RHEL 6 (2010-11-10): 5.10? 5.12?
* RHEL 7 (Fedora 19 - 2013-07-02): 5.16.3
---
class: center, middle, inverse
# Perl 5.10
## 2007-12-18
---
class: middle, center
# `use feature`
## Import new features
---
class: middle
# Import a single feature
```perl
use feature qw( say );
say "Hello, World!";
```
---
class: middle
# Import a bundle of features
```perl
use feature qw( :5.10 );
given ( $^V ) {
when ( $_ lt v5.14 ) {
say "Hello, history!";
}
when ( $_ gt v5.14 ) {
say "Hello, future!";
}
}
```
---
class: middle, center
# `say`
## Print with newline
`use feature qw( say )`
`use feature qw( :5.10 )`
---
class: middle
# Say
```perl
print "Hello, World!\n";
```
```perl
use feature qw( say );
say "Hello, World!";
```
---
class: middle, center
# `state` variables
## Keep a value between calls to a sub
`use feature qw( state )`
`use feature qw( :5.10 )`
---
class: middle
# State
.code-half[
.center[Before]
```perl
my $i = 0;
sub plus_i {
print "$i\n";
$i++;
}
plus_i() for 1..5;
```
]
.code-half[
.center[After]
```perl
use feature qw( state say );
sub plus_x {
state $x = 0;
say $x;
$x++;
}
plus_x() for 1..5;
```
]
---
class: middle, center
# `//`
## Defined-or
No use required
---
# Defined-or
```perl
use feature qw( say );
sub false_default {
say shift || "Default";
}
sub defined_default {
say shift // "Default";
}
false_default( 1 );
false_default( 0 );
false_default( );
defined_default( 1 );
defined_default( 0 );
defined_default( );
```
.center[Fun fact: This syntax highlighter doesn't understand defined-or!]
---
class: middle, center
# `given/when`
## Switch
`use feature qw( switch )`
`use feature qw( :5.10 )`
---
class: middle
.code-half[
# If
```perl
sub condition {
my ( $foo ) = @_;
if ( $foo =~ /^FX/ ) {
say "Foreign Exchange!";
}
elsif ( $foo =~ /^UST/ ) {
say "US Treasuries";
}
else {
say "Unknown!";
}
}
```
]
.code-half[
# Given
```perl
use feature qw( switch );
sub given_when {
my ( $foo ) = @_;
given ( $foo ) {
when ( /^FX/ ) {
say "Foreign Exchange";
}
when ( /^UST/ ) {
say "US Treasuries";
}
default {
say "Unknown!";
}
}
}
```
]
---
class: middle
# For/When
```perl
use feature qw( switch );
sub for_when {
for ( @_ ) {
when ( /^FX/ ) {
say "Foreign Exchange";
}
when ( /^UST/ ) {
say "US Treasuries";
}
default {
say "Unknown!";
}
}
}
```
---
class: middle, center
# Regex Named Groups
## Less magic, more descriptive
`(?<name>...)` `\g{name}` `$+{name}`
---
class: middle
# Regex Named Groups
.code-half[
```perl
use feature qw( say );
my $in = "foo: bar\nbaz: biz";
my $old_parse = qr{
([^:\s]+)
:
\s*
([^\n]+)
}x;
while ( $in =~ /$old_parse/g ) {
say "Key: $1";
say "Value: $2";
}
```
]
.code-half[
```perl
use feature qw( say );
my $in = "foo: bar\nbaz: biz";
my $new_parse = qr{
(?<key>[^:\s]+)
:
\s*
(?<value>[^\n]+)
}x;
while ( $in =~ /$new_parse/g ) {
say "Key: $+{key}";
say "Value: $+{value}";
}
```
]
---
class: middle, center
# Recursive Regex
## Turn regex into parsers
`(?1)` `(?-1)` `(?&name)`
---
class: middle
# Recursive Regex
.code-half[
```perl
use feature qw( say );
my $in = "[ [ 1 2 ] 3 [ 4 5 ] ]";
# INT -> \d+
# LIST -> "[" (LIST|INT)* "]"
my $parse = qr(
(?<LIST>
\s* \[ \s*
(?:
(?&LIST)
|
(?<INT>\d+)
\s*
)*
\s* \] \s*
)*
)x;
```
]
.code-half[
```perl
$in =~ $parse;
use Data::Dumper;
say Dumper \%+;
```
]
---
class: middle, center
# Module::CoreList
## Perl core modules, features, and releases
`corelist`
---
class: middle
# corelist
* `corelist Module` - Which Perl first had Module?
* `corelist -f X` - Which feature bundle is X in?
* `corelist -r` - Perl releases
---
class: center, middle, inverse
# Perl 5.12
## 2010-04-12
---
class: center, middle
# `...`
## Yada-yada-yada
No `use feature` needed
---
class: middle
# Yada-yada-yada
```perl
use feature qw( say );
sub foo { die "Unimplemented" }
eval { foo(); };
say "foo(): $@";
sub bar { ... }
eval { bar(); };
say "bar(): $@";
```
---
class: center, middle
# `each @array; keys @array; values @array;`
No `use feature` needed
---
class: middle
# Arrays are Key/Value Pairs
```perl
use feature qw( say );
my @array = qw( foo bar baz );
say 'C-style for loop';
for ( my $i = 0; $i < @array; $i++ ) {
say "$i: $array[$i]";
}
say 'List of indicies';
for my $i ( 0..$#array ) {
say "$i: $array[$i]";
}
say 'each @array';
while ( my ( $k, $v ) = each @array ) {
say "$k: $v";
}
say 'keys @array';
say join ", ", keys @array;
say 'values @array';
say join ", ", values @array;
```
---
class: center, middle
# `autodie`
## Never forget to check errors again!
`use autodie`
---
class: middle
# autodie
```perl
sub old {
open my $fh, '<', 'DOESNOTEXIST'
or die "Can't open 'DOESNOTEXIST' for reading: '$!'";
}
sub new {
use autodie;
open my $fh, '<', 'DOESNOTEXIST';
}
use feature qw( say );
eval { old(); };
say "old(): $@";
eval { new(); };
say "new(): $@";
```
---
class: center, middle, inverse
# Perl 5.14
## 2011-05-14
---
class: center, middle
# `s///r`
## Non-destructive substitution
No `use feature` required
---
class: middle
# Non-destructive substitution
```perl
use feature qw( say );
sub old_change {
my ( $to_change ) = @_;
my $changed = $to_change;
$changed =~ s/foo/bar/;
say "$to_change -> $changed";
}
sub new_change {
my ( $to_change ) = @_;
my $changed = $to_change =~ s/foo/bar/r;
say "$to_change -> $changed";
}
old_change( "foo" );
new_change( "foo" );
```
---
class: middle
# Best used in map()
```perl
use feature qw( say );
my @array = qw( fooo baro bazo );
sub old {
say for map { my $x = $_; $x =~ s/o/0/; $x } @_;
}
sub new {
say for map { s/o/0/r } @_;
}
say "old()";
old( @array );
say "new()";
new( @array );
```
---
class: center, middle
# More reliable exception throwing
## `DESTROY` can't change `$@`
---
class: middle
# 2 Ways to Die
```perl
use warnings;
use feature qw( say );
package Foo;
sub new { bless {}, "Foo" }
sub DESTROY { eval { die "It's clobberin' time!" } }
package main;
eval {
my $foo = Foo->new;
die "Avengers Assemble!";
};
say $@;
```
---
class: middle
# Which One Will It Be?
```
$ perlbrew exec --with perl-5.12.5,perl-5.14.4 perl 5.14/eval-destroy.pl
perl-5.12.5
==========
It's clobberin' time! at 5.14/eval-destroy.pl line 6.
perl-5.14.4
==========
Avengers Assemble! at 5.14/eval-destroy.pl line 12.
```
---
class: center, middle
# `HTTP::Tiny`
## Simple core HTTP client
`use HTTP::Tiny`
---
class: middle
# No more LWP::Simple
```perl
use feature qw( say );
use HTTP::Tiny;
my $resp = HTTP::Tiny->new->get( 'http://example.com' );
say $resp->{content};
```
---
class: center, middle
# `JSON::PP`
## Simple core JSON parser
`use JSON::PP`
---
class: middle
# JSON
```perl
use feature qw( say );
use JSON::PP;
my $json = '{ "foo": "bar", "baz": "fuzz" }';
my $hash = JSON::PP->new->decode( $json );
say "foo: " . $hash->{foo};
```
---
class: center, middle, inverse
# Perl 5.16
## 2012-05-26
---
class: center, middle
# `__SUB__`
## Reference to the current running sub
No `use feature` needed
---
class: middle
# Recurse Without Names
```perl
use feature qw( say );
my $old; $old = sub {
my ( $i ) = @_;
return $i if $i <= 1;
return $old->( $i - 1 ) + $old->( $i - 2 );
};
# Hello memory leak!
my $new = sub {
my ( $i ) = @_;
return $i if $i <= 1;
return __SUB__->( $i - 1 ) + __SUB__->( $i - 2 );
};
say $old->( 3 );
say $new->( 3 );
```
---
class: center, middle, inverse
# Perl 5.18
## 2013-05-18
---
class: center, middle
# `my sub`, `our sub`, `state sub`
## Lexical subroutines
`use feature qw( lexical_subs )`
---
class: middle
# My subs, Your subs
```perl
use feature qw( say lexical_subs );
sub old {
say "old()";
my $inner = sub {
say "inner()";
};
$inner->();
}
sub new {
say "new()";
my sub inner {
say "inner()";
}
inner();
}
old();
new();
```
---
class: middle
# Hide your subs
```perl
use feature qw( say lexical_subs );
sub new {
say "new()";
my sub inner {
say "inner()";
}
inner();
}
sub hide {
my sub new {
say "hidden new()";
}
new();
}
new();
hide();
```
---
class: center, middle, inverse
# Perl 5.20
## Coming in 2014
---
class: center, middle
# `%hash{...}`, `%array[...]`
## Hash-based slices
No `use feature` needed
---
class: middle
# Hash/Array in, Hash out
```perl
use feature qw( say );
my %hash = ( foo => 0, bar => 1 );
my @array = qw( foo bar );
my %old_part_hash = map { $_ => $hash{$_} }
grep { $_ eq 'foo' }
keys %hash;
my %part_hash = %hash{"foo"};
say "part_hash{foo} -> $part_hash{foo}";
my %part_array = %array[0];
say "part_array{0} -> $part_array{0}";
```
---
class: center, middle
# `$hash_ref->%*`, `$ary_ref->@*`
## Postfix dereference operators
---
class: middle
# Read From Left to Right
```perl
my $href = {
foo => "bar",
};
my $aref = [ "foo", "bar" ];
say %{ $href };
say $href->%*;
say @{ $aref };
say $aref->@*;
```
---
class: middle
# Deep Diving Dereference
```perl
say %{ $data->{results}[0]{symbols} };
```
```perl
say $data->{results}[0]{symbols}->%*
```
---
class: middle
# Postfix Slicing
```perl
say @{ $data->{results} }[0..3]
```
```perl
say $data->{results}->@[0..3];
```
---
class: center, middle
# `sub foo( $bar, @baz );`
## Subroutine signatures
`use feature qw( signatures );`
---
class: middle
# Unpack @_ automatically
```perl
use feature qw( say signatures );
sub old {
my ( $bar, @baz ) = @_;
die "First argument missing" unless $bar;
say "$bar -> @baz";
}
sub new( $bar, @baz ) {
say "$bar -> @baz";
}
old( "foo" );
eval { old() };
say "old(): $@";
new( "foo" );
eval { new() };
say "new(): $@";
```
---
class: center, middle, inverse
# Questions!
</textarea>
<div id="slideshow"></div>
</body>
</html>