Slideshare.net (beta)

 
Post: 
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons

All comments

Add a comment on Slide 1

If you have a SlideShare account, login to comment; else you can comment as a guest


Showing 1-50 of 18 (more)

Perl 5.10 for People Who Aren't Totally Insane

From rjbs, 7 months ago

All the hype about perl 5.10 can sound a little intimidating. User more

37163 views  |  17 comments  |  17 favorites  |  1153 downloads  |  61 embeds (Stats)
 

Groups/Events

 
 

Privacy InfoNew!

This slideshow is Public

 
Embed in your blog
Embed (wordpress.com)

Slideshow Statistics
Total Views: 37163
on Slideshare: 37027
from embeds: 136* * Views from embeds since 21 Aug, 07

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 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{ $self } = shift; for my $old_id ( keys %OBJ ) { } else { return $size{ $self }; 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 90: 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 = $OBJECT_REGISTRY } else { { $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 91: Field Hashes Hash::Util::FieldHash

Slide 92: Field Hashes - they’re just like hashes Hash::Util::FieldHash

Slide 93: Field Hashes - they’re just like hashes - objects as keys become object ids Hash::Util::FieldHash

Slide 94: Field Hashes - they’re just like hashes - objects as keys become object ids - but get destroyed and cloned Hash::Util::FieldHash

Slide 95: Field Hashes fieldhash my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash

Slide 96: Field Hashes sub size { my $self = shift; fieldhash state %size; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash

Slide 97: Alternate Regex Engines perlreapi

Slide 98: Alternate Regex Engines - lets you change how regex work - but not how you use them (=~, etc) s///, perlreapi

Slide 99: Alternate Regex Engines [whitelist] to = root re::engine::POSIX

Slide 100: Alternate Regex Engines [whitelist] to = root|abuse re::engine::POSIX

Slide 101: Alternate Regex Engines my $config = Config::INI::Reader->read_file($cfg); like( ‘abuse@postmaster.com’, qr/$cfg->{whitelist}{to}/, “abuse is whitelisted”, ); re::engine::POSIX

Slide 102: Alternate Regex Engines [whitelist] to = root|abuse re::engine::POSIX

Slide 103: Alternate Regex Engines my $config = Config::INI::Reader->read_file($cfg); like( ‘abuse@postmaster.com’, qr/$cfg->{whitelist}{to}/, “abuse is whitelisted”, ); re::engine::POSIX

Slide 104: Alternate Regex Engines my $config = Config::INI::Reader->read_file($cfg); use re::engine::POSIX; like( ‘abuse@postmaster.com’, qr/$cfg->{whitelist}{to}/, “abuse is whitelisted”, ); re::engine::POSIX

Slide 105: http://www.perl.org/get.html

Slide 106: Any questions?