Slideshow transcript
Slide 1: Perl 5.10
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? - lexically scoped user pragmata! - pluggable regex compilation engines! - trie-based non-recursive pattern matching! - thread-safe weak refkey hashes! perl51000delta
Slide 12: Yes, You Care perl51000delta
Slide 13: Yes, You Care - Not everything in 5.10 is esoteric. perl51000delta
Slide 14: Yes, You Care - Not everything in 5.10 is esoteric. - Not everything in 5.10 is for gurus. perl51000delta
Slide 15: 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 16: 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 17: First: A Warning feature
Slide 18: First: A Warning - 5.10 is backwards compatible feature
Slide 19: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators feature
Slide 20: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default feature
Slide 21: 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 22: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - read the perldoc feature
Slide 23: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - read the perldoc Hi! I'm a perldoc reference! feature
Slide 24: First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - read the perldoc feature
Slide 25: say $what - new built-in, say - it’s like print - but it adds a newline for you perlfunc
Slide 26: say $what print “Hello, world!\\n”; print “$message\\n”; print “$_\\n” for @lines; perlfunc
Slide 27: say $what print “Hello, world!\\n”; say “Hello, world!”; print “$message\\n”; print “$_\\n” for @lines; perlfunc
Slide 28: say $what print “Hello, world!\\n”; say “Hello, world!”; print “$message\\n”; say $message; print “$_\\n” for @lines; perlfunc
Slide 29: say $what print “Hello, world!\\n”; say “Hello, world!”; print “$message\\n”; say $message; print “$_\\n” for @lines; say for @lines; perlfunc
Slide 30: truth and definedness perlop
Slide 31: truth and definedness sub record_sale { perlop
Slide 32: truth and definedness sub record_sale { my ($product, $amount) = @_; perlop
Slide 33: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; perlop
Slide 34: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... perlop
Slide 35: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... } perlop
Slide 36: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount = defined $amount ? $amount : $product->cost; ... } perlop
Slide 37: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... } perlop
Slide 38: truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... } perlop
Slide 39: the new OR operator sub record_sale { my ($product, $amount) = @_; $amount //= $product->cost; ... } perlop
Slide 40: the new OR operator $setting = defined $given ? $given : $default; perlop
Slide 41: the new OR operator $setting = $given; unless (defined $setting) { $setting = $default; } perlop
Slide 42: the new OR operator $setting = $given || $default; perlop
Slide 43: the new OR operator $setting = $given // $default; perlop
Slide 44: State Variables $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } perlsub
Slide 45: State Variables my $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } perlsub
Slide 46: State Variables { my $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } } perlsub
Slide 47: 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 48: State Variables { my $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } } perlsub
Slide 49: State Variables sub read_line { state $lines_left = 100; die “trial period expired” unless $lines_left-- > 0; ... } perlsub
Slide 50: Stackable File Tests if ( -f $file and -w $file and -z $file ){ unlink $file; } perlfunc
Slide 51: Stackable File Tests if ( -f $file and -w _ and -z _ ){ unlink $file; } perlfunc
Slide 52: Stackable File Tests if (-f -w -z $file) { unlink $file; } perlfunc
Slide 53: Regex: Named Captures perlre
Slide 54: Regex: Named Captures - find matches by name, not position perlre
Slide 55: Regex: Named Captures - find matches by name, not position - avoid the dreaded$1 perlre
Slide 56: Regex: Named Captures - find matches by name, not position - avoid the dreaded $1 - no longer second to Python or .Net! perlre
Slide 57: Regex: Named Captures # our hypothetical format section:property = value perlre
Slide 58: Regex: Named Captures $line =~ /(\\w+):(\\w+) = (\\w+)/; $name = $2; $value = $3; perlre
Slide 59: Regex: Named Captures $lhs_re = qr/(\\w+):(\\w+)/; $rhs_re = qr/(\\w+)/; $line =~ /$lhs_re = $rhs_re/; $name = $2; $value = $3; perlre
Slide 60: Regex: Named Captures $line =~ /$lhs_re = $rhs_re/; $name = $2; $value = $3; perlre
Slide 61: Regex: Named Captures $line =~ /$lhs_re = $rhs_re/; $name = $+{ name }; $value = $+{ value }; perlre
Slide 62: Regex: Named Captures $lhs_re = qr/(\\w+):(\\w+)/; $rhs_re = qr/(\\w+)/; perlre
Slide 63: Regex: Named Captures $lhs_re = qr/(\\w+):(?<name>\\w+)/; $rhs_re = qr/(?<value>\\w+)/; perlre
Slide 64: Better Error Message(s) $str = “Greetings, $name. Your last login was $last. It is now $time.”; perldiag
Slide 65: 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 66: 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 67: Smart Matching perlsyn
Slide 68: Smart Matching - a new kind of comparison operator perlsyn
Slide 69: Smart Matching - a new kind of comparison operator - its behavior depends on its inputs perlsyn
Slide 70: Smart Matching - a new kind of comparison operator - its behavior depends on its inputs - “if these two things match...” perlsyn
Slide 71: 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 72: Smart Matching perlsyn
Slide 73: Smart Matching if ($foo ~~ undef) { ... } perlsyn
Slide 74: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } perlsyn
Slide 75: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } perlsyn
Slide 76: Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } 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: Inside-Out Objects Hash::Util::FieldHash
Slide 81: Inside-Out Objects - traditional objects are a hashref Hash::Util::FieldHash
Slide 82: Inside-Out Objects - traditional objects are a hashref - look up attrs in the obj itself by attr name Hash::Util::FieldHash
Slide 83: 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 84: 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 85: 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 86: Inside-Out Objects my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
Slide 87: Inside-Out Objects my %size; sub size { my $self = shift; my $id = refaddr $self; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
Slide 88: Inside-Out Objects my %size; sub size { my $self = shift; my $id = refaddr $self; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } sub DESTROY { my $id = refaddr $_[0]; delete $size{ $id }; } Hash::Util::FieldHash
Slide 89: Inside-Out


Add a comment on Slide 1
If you have a SlideShare account, login to comment; else you can comment as a guest- Favorites & Groups
Showing 1-50 of 21 (more)