Loading...
Flash Player 9 (or above) is needed to view slideshows. We have detected that you do not have it on your computer.To install it, go here
- All Comments (0)
- Notes on Slide 1
-
bayashi favorited this 3 weeks ago
-
erezschatz favorited this 4 months ago -
rfc1036 favorited this 5 months ago -
mobil favorited this 6 months ago -
membogg favorited this 7 months ago -
vinayakh favorited this 7 months ago -
redwhitered favorited this 8 months ago -
vioan favorited this 9 months ago -
naveeng favorited this 9 months ago
-
sopan_shewale favorited this 11 months ago
-
mofoghlu favorited this 11 months ago -
schwern favorited this 11 months ago
-
davorg favorited this 2 years ago
-
pjf favorited this 2 years ago
-
dpavlin favorited this 2 years ago
-
kevinold favorited this 2 years ago -
jjmerelo favorited this 2 years ago -
aloof.schipperke favorited this 2 years ago
-
thomasfahle favorited this 2 years ago
-
chorny favorited this 2 years ago -
-
larsen favorited this 2 years ago
Slideshow Transcript
- Slide 1: Perl 5.10 for people who are not insane
- Slide 2: Perl 5.10 for people who are not totally insane
- Slide 3: 5.10 isn’t like 5.8.x perl5100delta
- Slide 4: 5.10 isn’t like 5.8.x - features only get added in new 5.x releases perl5100delta
- Slide 5: 5.10 isn’t like 5.8.x - features only get added in new 5.x releases - it’s been 5 years since the last release (5.8) perl5100delta
- Slide 6: 5.10 is Way Cool perl51000delta
- Slide 7: 5.10 is Way Cool - no significant new features in Perl since 2002 perl51000delta
- Slide 8: 5.10 is Way Cool - no significant new features in Perl since 2002 - remember how bad you wanted to see Star Wars: Episode 1? perl51000delta
- Slide 9: 5.10 is Way Cool - no significant new features in Perl since 2002 - remember how bad you wanted to see Star Wars: Episode 1? - that’s how excited you should be for 5.10 perl51000delta
- Slide 10: 5.10 is Way Cool - no significant new features in Perl since 2002 - remember how bad you wanted to see Star Wars: Episode 1? - that’s how excited you should be for 5.10 - but it won’t suck (no POD race scene) perl51000delta
- Slide 11: Lexicascopasmartwhat? perl51000delta
- Slide 12: Lexicascopasmartwhat? - lexically scoped user pragmata! perl51000delta
- Slide 13: Lexicascopasmartwhat? - lexically scoped user pragmata! - pluggable regex compilation engines! perl51000delta
- Slide 14: Lexicascopasmartwhat? - lexically scoped user pragmata! - pluggable regex compilation engines! - trie-based non-recursive pattern matching! perl51000delta
- Slide 15: Lexicascopasmartwhat? - lexically scoped user pragmata! - pluggable regex compilation engines! - trie-based non-recursive pattern matching! - thread-safe weak refkey hashes! perl51000delta
- Slide 16: Yes, You Care perl51000delta
- Slide 17: Yes, You Care - Not everything in 5.10 is esoteric. perl51000delta
- Slide 18: Yes, You Care - Not everything in 5.10 is esoteric. - Not everything in 5.10 is for gurus. perl51000delta
- Slide 19: Yes, You Care - Not everything in 5.10 is esoteric. - Not everything in 5.10 is for gurus. - Not everything in 5.10 is for C programmers. perl51000delta
- Slide 20: Yes, You Care - Not everything in 5.10 is esoteric. - Not everything in 5.10 is for gurus. - Not everything in 5.10 is for C programmers. - Not everything in 5.10 is super advanced. perl51000delta
- Slide 21: First: A Warning feature
- Slide 22: First: A Warning - 5.10 is backwards compatible feature
- Slide 23: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators feature
- Slide 24: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default feature
- Slide 25: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; feature
- Slide 26: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.010; feature
- Slide 27: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.010; - read the perldoc feature
- Slide 28: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.010; - read the perldoc I’m a perldoc ref! feature
- Slide 29: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.010; - read the perldoc feature
- Slide 30: say what
- Slide 31: say $what - new built-in, say - it’s like print - but it adds a newline for you perlfunc
- Slide 32: say $what perlfunc
- Slide 33: say $what print “Hello, world!\\n”; perlfunc
- Slide 34: say $what print “Hello, world!\\n”; print “$message\\n”; perlfunc
- Slide 35: say $what print “Hello, world!\\n”; print “$message\\n”; print “$_\\n” for @lines; perlfunc
- Slide 36: say $what print “Hello, world!\\n”; say “Hello, world!”; print “$message\\n”; print “$_\\n” for @lines; perlfunc
- Slide 37: say $what print “Hello, world!\\n”; say “Hello, world!”; print “$message\\n”; say $message; print “$_\\n” for @lines; perlfunc
- Slide 38: say $what print “Hello, world!\\n”; say “Hello, world!”; print “$message\\n”; say $message; print “$_\\n” for @lines; say for @lines; perlfunc
- Slide 39: truth and definedness
- Slide 40: truth and definedness perlop
- Slide 41: truth and definedness sub record_sale { perlop
- Slide 42: truth and definedness sub record_sale { my ($product, $amount) = @_; perlop
- Slide 43: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; perlop
- Slide 44: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... perlop
- Slide 45: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... } perlop
- Slide 46: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount = defined $amount ? $amount : $product->cost; ... } perlop
- Slide 47: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... } perlop
- Slide 48: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... } perlop
- Slide 49: the new OR operator sub record_sale { my ($product, $amount) = @_; $amount //= $product->cost; ... } perlop
- Slide 50: the new OR operator $setting = defined $given ? $given : $default; perlop
- Slide 51: the new OR operator $setting = $given; unless (defined $setting) { $setting = $default; } perlop
- Slide 52: the new OR operator $setting = $given || $default; perlop
- Slide 53: the new OR operator $setting = $given // $default; perlop
- Slide 54: keeping state
- Slide 55: State Variables $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } perlsub
- Slide 56: State Variables my $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } perlsub
- Slide 57: State Variables { my $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } } perlsub
- Slide 58: State Variables package Trial::Period; sub new { my ($class, $arg) = @_; my $guts = { lines_left => $arg->{lines}, error_msg => $arg->{error}, }; return bless $guts => $class; } my $LINES = 100; my $ERROR = “sorry, trial period over”; sub consume_line { my $TRIAL = Trial::Period->new({ my ($self) = @_; lines => $LINES, $self->{lines_left}--; error => $ERROR, } }); sub lines_left { sub read_line { my ($self) = @_; $TRIAL->assert_lines_left; return $self->{lines_left}; ... } } sub assert_lines_left { my ($self) = @_; unless ($self->lines_left) { die $self->{error_msg}; } } 1; perlsub
- Slide 59: State Variables { my $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } } perlsub
- Slide 60: State Variables sub read_line { state $lines_left = 100; die “trial period expired” unless $lines_left-- > 0; ... } perlsub
- Slide 61: -x stacking
- Slide 62: Stackable File Tests if ( -f $file and -w $file and -z $file ) { unlink $file; } perlfunc
- Slide 63: Stackable File Tests if ( -f $file and -w _ and -z _ ) { unlink $file; } perlfunc
- Slide 64: Stackable File Tests if (-f -w -z $file) { unlink $file; } perlfunc
- Slide 65: smart matching
- Slide 66: Smart Matching perlsyn
- Slide 67: Smart Matching - a new kind of comparison operator perlsyn
- Slide 68: Smart Matching - a new kind of comparison operator - its behavior depends on its inputs perlsyn
- Slide 69: Smart Matching - a new kind of comparison operator - its behavior depends on its inputs - “if these two things match...” perlsyn
- Slide 70: Smart Matching - a new kind of comparison operator - its behavior depends on its inputs - “if these two things match...” - hard to tell, easy to show... perlsyn
- Slide 71: Smart Matching perlsyn
- Slide 72: Smart Matching if ($foo ~~ undef) { ... } perlsyn
- Slide 73: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } perlsyn
- Slide 74: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } perlsyn
- Slide 75: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } perlsyn
- Slide 76: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } elsif ($foo ~~ qr/re/) { ... } perlsyn
- Slide 77: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } elsif ($foo ~~ qr/re/) { ... } elsif ($foo ~~ $bar) { ... } perlsyn
- Slide 78: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } elsif ($foo ~~ qr/re/) { ... } elsif ($foo ~~ $bar) { ... } else { ... } perlsyn
- Slide 79: Smart Matching given ($foo) { when (undef) { ... } when (@array) { ... } when ($code) { ... } when (%hash) { ... } when (qr/re/) { ... } when ($bar) { ... } default { ... } } perlsyn
- Slide 80: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } elsif ($foo ~~ qr/re/) { ... } elsif ($foo ~~ $bar) { ... } else { ... } perlsyn
- Slide 81: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ $array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ $hash) { ... } elsif ($foo ~~ qr/re/) { ... } elsif ($foo ~~ $bar) { ... } else { ... } perlsyn
- Slide 82: Smart Matching my $test; perlsyn
- Slide 83: Smart Matching given ($foo) { when (undef) { ... } when ($aref) { ... } when ($code) { ... } when ($href) { ... } when ($regex) { ... } when ($object) { ... } default { ... } } perlsyn
- Slide 84: Smart Matching given ($foo) { when ($test_1) { ... } when ($test_2) { ... } when ($test_3) { ... } when ($test_4) { ... } when ($test_5) { ... } when ($test_6) { ... } default { ... } } perlsyn
- Slide 85: Smart Matching perlsyn
- Slide 86: Smart Matching @want = @have->where($test) perlsyn
- Slide 87: Smart Matching @want = @have->where($test) @want = @have->where(sub{ …… }) perlsyn
- Slide 88: Smart Matching @want = @have->where($test) @want = @have->where(sub{ …… }) @want = @have->where(qr/.../sm) perlsyn
- Slide 89: Smart Matching @want = @have->where($test) @want = @have->where(sub{ …… }) @want = @have->where(qr/.../sm) @want = @have->where([ 1,2,3 ]) perlsyn
- Slide 90: Smart Matching perlsyn
- Slide 91: Smart Matching sub where { perlsyn
- Slide 92: Smart Matching sub where { my ($array, $test) = @_; perlsyn
- Slide 93: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { perlsyn
- Slide 94: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; perlsyn
- Slide 95: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; perlsyn
- Slide 96: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } perlsyn
- Slide 97: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { perlsyn
- Slide 98: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; perlsyn
- Slide 99: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } perlsyn
- Slide 100: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { perlsyn
- Slide 101: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { return grep { $test->($_) } @$array; perlsyn
- Slide 102: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { return grep { $test->($_) } @$array; } perlsyn
- Slide 103: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { return grep { $test->($_) } @$array; } die “invalid test” perlsyn
- Slide 104: Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { return grep { $test->($_) } @$array; } die “invalid test” } perlsyn
- Slide 105: Smart Matching sub where { my ($array, $test) = @_; grep { $_ ~~ $test } @$array; } perlsyn
- Slide 106: Smart Matching SmartMatch::Sugar perlsyn
- Slide 107: Smart Matching SmartMatch::Sugar @want = @have->where( hash ) perlsyn
- Slide 108: Smart Matching SmartMatch::Sugar @want = @have->where( hash ) @want = @have->where( class ) perlsyn
- Slide 109: Smart Matching SmartMatch::Sugar @want = @have->where( hash ) @want = @have->where( class ) @want = @have->where(isa(‘Foo’)) perlsyn
- Slide 110: unknown undefined
- Slide 111: Better Error Message(s) $str = “Greetings, $name. Your last login was $last. It is now $time.”; perldiag
- Slide 112: Better Error Message(s) $str = “Greetings, $name. Your last login was $last. It is now $time.”; Use of uninitialized value in concatenation (.) or string at hello.plx line 9. perldiag
- Slide 113: Better Error Message(s) $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. perldiag
- Slide 114: inside-out objects
- Slide 115: Inside-Out Objects Hash::Util::FieldHash
- Slide 116: Inside-Out Objects - traditional objects are a hashref Hash::Util::FieldHash
- Slide 117: Inside-Out Objects - traditional objects are a hashref - look up attrs in the obj itself by attr name Hash::Util::FieldHash
- Slide 118: Inside-Out Objects - traditional objects are a hashref - look up attrs in the obj itself by attr name - inside-out objects are content-free refs Hash::Util::FieldHash
- Slide 119: Inside-Out Objects - traditional objects are a hashref - look up attrs in the obj itself by attr name - inside-out objects are content-free refs - look up attrs in an external hash by obj id Hash::Util::FieldHash
- Slide 120: Inside-Out Objects - traditional objects are a hashref - look up attrs in the obj itself by attr name - inside-out objects are content-free refs - look up attrs in an external hash by obj id - there are complications for inside-out objects Hash::Util::FieldHash
- Slide 121: Inside-Out Objects sub size { my $self = shift; if (@_) { return $self->{size} = shift; } else { return $self->{size}; } } Hash::Util::FieldHash
- Slide 122: Inside-Out Objects my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
- Slide 123: Inside-Out Objects my %size; sub size { my $self = shift; my $id = refaddr $self; if (@_) { return $size{ $id } = shift; } else { return $size{ $id }; } } Hash::Util::FieldHash
- Slide 124: Inside-Out Objects my %size; sub size { my $self = shift; my $id = refaddr $self; if (@_) { return $size{ $id } = shift; } else { return $size{ $id }; } } sub DESTROY { my $id = refaddr $_[0]; delete $size{ $id }; } Hash::Util::FieldHash
- Slide 125: Inside-Out Objects my %size; sub CLONE { sub size { my $class = shift; my $self = shift; my $id = refaddr $self; my @properties = map { values %$_ } values %PROP_DATA_FOR; if (@_) { return $size{ $id } = shift; for my $old_id ( keys %OBJ ) { } else { return $size{ $id }; my $object = $OBJ{ $old_id }; } my $new_id = refaddr $object; } for my $prop ( @properties ) { sub DESTROY { next unless exists $prop->{ $old }; my $id = refaddr $_[0]; $prop->{ $new } = $prop->{ $old }; delete $size{ $id }; delete $prop->{ $old }; } } weaken ( $OBJ{ $new } = $object ); delete $OBJ{ $old }; } } Hash::Util::FieldHash
- Slide 126: Inside-Out Objects my %OBJECT_REGISTRY; sub CLONE { my %size; my $class = shift; sub size { my $self = shift; my @properties = map { values %$_ } my $id = refaddr $self; values %PROP_DATA_FOR; $self->register_object; for my $old_id ( keys %OBJECT_REGISTRY ) { if (@_) { return $size{ $self } = shift; my $object = } else { $OBJECT_REGISTRY{ $old_id }; return $size{ $self }; my $new_id = refaddr $object; } } for my $prop ( @properties ) { next unless exists $prop- sub DESTROY { >{ $old_id }; my $id = refaddr $_[0]; $prop->{ $new_id } = $prop- delete $size{ $id }; >{ $old_id }; delete $OBJECT_REGISTRY{ $id }; delete $prop->{ $old_id }; } } sub register_object { weaken ( $OBJECT_REGISTRY{ $new_id } = my ($self) = @_; $object ); my $id = refaddr $self; delete $OBJECT_REGISTRY{ $old_id }; $OBJECT_REGISTRY{ $id } = $self; } } } Hash::Util::FieldHash
- Slide 127: Field Hashes Hash::Util::FieldHash
- Slide 128: Field Hashes - they’re just like hashes Hash::Util::FieldHash
- Slide 129: Field Hashes - they’re just like hashes - objects as keys become object ids Hash::Util::FieldHash
- Slide 130: Field Hashes - they’re just like hashes - objects as keys become object ids - but get destroyed and cloned Hash::Util::FieldHash
- Slide 131: Field Hashes my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
- Slide 132: Field Hashes fieldhash my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
- Slide 133: Field Hashes { fieldhash my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } } Hash::Util::FieldHash
- Slide 134: Field Hashes sub size { my $self = shift; fieldhash state %size; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
- Slide 135: lexical topic
- Slide 136: (topic is how you say $_)
- Slide 137: Lexical Topic for (@lines) { chomp; next if /^#/; next unless length; s/a/b/; sanity_check; say; } perlvar
- Slide 138: Lexical Topic for my $line (@lines) { chomp $line; next if $line ~~ /^#/; next unless length $line; $line =~ s/a/b/; sanity_check($line); say $line; } perlvar
- Slide 139: Lexical Topic for my $_ (@lines) { chomp; next if /^#/; next unless length; s/a/b/; sanity_check; say; } perlvar
- Slide 140: Regex
- Slide 141: named captures
- Slide 142: Regex: Named Captures perlre
- Slide 143: Regex: Named Captures - find matches by name, not position perlre
- Slide 144: Regex: Named Captures - find matches by name, not position - avoid the dreaded$1 perlre
- Slide 145: Regex: Named Captures - find matches by name, not position - avoid the dreaded $1 - no longer second to Python or .Net! perlre
- Slide 146: Regex: Named Captures # our hypothetical format section:property = value perlre
- Slide 147: Regex: Named Captures $line ~~ /(\\w+):(\\w+) = (\\w+)/; $name = $2; $value = $3; perlre
- Slide 148: Regex: Named Captures $lhs_re = qr/(\\w+):(\\w+)/; $rhs_re = qr/(\\w+)/; $line ~~ /$lhs_re = $rhs_re/; $name = $2; $value = $3; perlre
- Slide 149: Regex: Named Captures $line ~~ /$lhs_re = $

