Perl 5.10 for People Who Aren't Totally Insane
-
Upload
ricardo-signes -
Category
Business
-
view
84.309 -
download
1
description
Transcript of Perl 5.10 for People Who Aren't Totally Insane
![Page 1: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/1.jpg)
Perl 5.10insanefor people who are not
![Page 2: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/2.jpg)
Perl 5.10insanetotallyfor people who are not
![Page 3: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/3.jpg)
perl5100delta
5.10 isn’t like 5.8.x
![Page 4: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/4.jpg)
perl5100delta
5.10 isn’t like 5.8.x
- features only get added in new 5.x releases
![Page 5: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/5.jpg)
perl5100delta
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)
![Page 6: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/6.jpg)
perl51000delta
5.10 is Way Cool
![Page 7: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/7.jpg)
perl51000delta
5.10 is Way Cool
- no significant new features in Perl since 2002
![Page 8: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/8.jpg)
perl51000delta
5.10 is Way Cool
- no significant new features in Perl since 2002
- remember how bad you wanted to see Star Wars: Episode 1?
![Page 9: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/9.jpg)
perl51000delta
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
![Page 10: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/10.jpg)
perl51000delta
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)
![Page 11: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/11.jpg)
perl51000delta
Lexicascopasmartwhat?
![Page 12: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/12.jpg)
perl51000delta
Lexicascopasmartwhat?
- lexically scoped user pragmata!
![Page 13: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/13.jpg)
perl51000delta
Lexicascopasmartwhat?
- lexically scoped user pragmata!
- pluggable regex compilation engines!
![Page 14: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/14.jpg)
perl51000delta
Lexicascopasmartwhat?
- lexically scoped user pragmata!
- pluggable regex compilation engines!
- trie-based non-recursive pattern matching!
![Page 15: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/15.jpg)
perl51000delta
Lexicascopasmartwhat?
- lexically scoped user pragmata!
- pluggable regex compilation engines!
- trie-based non-recursive pattern matching!
- thread-safe weak refkey hashes!
![Page 16: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/16.jpg)
perl51000delta
Yes, You Care
![Page 17: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/17.jpg)
perl51000delta
Yes, You Care
- Not everything in 5.10 is esoteric.
![Page 18: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/18.jpg)
perl51000delta
Yes, You Care
- Not everything in 5.10 is esoteric.
- Not everything in 5.10 is for gurus.
![Page 19: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/19.jpg)
perl51000delta
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.
![Page 20: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/20.jpg)
perl51000delta
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.
![Page 21: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/21.jpg)
feature
First: A Warning
![Page 22: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/22.jpg)
feature
First: A Warning
- 5.10 is backwards compatible
![Page 23: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/23.jpg)
feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators
![Page 24: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/24.jpg)
feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators
- they’re not enabled by default
![Page 25: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/25.jpg)
feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators
- they’re not enabled by default
- use feature ‘mtfnpy’;
![Page 26: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/26.jpg)
feature
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;
![Page 27: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/27.jpg)
feature
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
![Page 28: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/28.jpg)
feature
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!
![Page 29: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/29.jpg)
feature
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
![Page 30: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/30.jpg)
say what
![Page 31: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/31.jpg)
perlfunc
- new built-in, say
- it’s like print
- but it adds a newline for you
say $what
![Page 32: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/32.jpg)
perlfunc
say $what
![Page 33: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/33.jpg)
perlfunc
say $what
print “Hello, world!\n”;
![Page 34: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/34.jpg)
perlfunc
say $what
print “Hello, world!\n”;
print “$message\n”;
![Page 35: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/35.jpg)
perlfunc
say $what
print “Hello, world!\n”;
print “$message\n”;
print “$_\n” for @lines;
![Page 36: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/36.jpg)
perlfunc
say $what
print “Hello, world!\n”;
print “$message\n”;
print “$_\n” for @lines;
say “Hello, world!”;
![Page 37: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/37.jpg)
perlfunc
say $what
print “Hello, world!\n”;
print “$message\n”;
print “$_\n” for @lines;
say “Hello, world!”;
say $message;
![Page 38: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/38.jpg)
perlfunc
say $what
print “Hello, world!\n”;
print “$message\n”;
print “$_\n” for @lines;
say “Hello, world!”;
say $message;
say for @lines;
![Page 39: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/39.jpg)
truth and definedness
![Page 40: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/40.jpg)
perlop
truth and definedness
![Page 41: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/41.jpg)
perlop
truth and definedness
sub record_sale {
![Page 42: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/42.jpg)
perlop
truth and definedness
sub record_sale { my ($product, $amount) = @_;
![Page 43: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/43.jpg)
perlop
truth and definedness
sub record_sale { my ($product, $amount) = @_;
$amount ||= $product->cost;
![Page 44: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/44.jpg)
perlop
truth and definedness
sub record_sale { my ($product, $amount) = @_;
$amount ||= $product->cost;
...
![Page 45: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/45.jpg)
perlop
truth and definedness
sub record_sale { my ($product, $amount) = @_;
$amount ||= $product->cost;
...}
![Page 46: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/46.jpg)
perlop
truth and definednesssub record_sale { my ($product, $amount) = @_;
$amount = defined $amount ? $amount : $product->cost;
...}
![Page 47: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/47.jpg)
perlop
truth and definedness
sub record_sale { my ($product, $amount) = @_;
$amount ||= $product->cost;
...}
![Page 48: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/48.jpg)
perlop
truth and definedness
sub record_sale { my ($product, $amount) = @_;
$amount ||= $product->cost;
...}
![Page 49: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/49.jpg)
perlop
the new OR operator
sub record_sale { my ($product, $amount) = @_;
$amount //= $product->cost;
...}
![Page 50: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/50.jpg)
perlop
the new OR operator
$setting = defined $given ? $given : $default;
![Page 51: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/51.jpg)
perlop
the new OR operator
$setting = $given;unless (defined $setting) { $setting = $default;}
![Page 52: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/52.jpg)
perlop
the new OR operator
$setting = $given || $default;
![Page 53: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/53.jpg)
perlop
the new OR operator
$setting = $given // $default;
![Page 54: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/54.jpg)
keeping state
![Page 55: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/55.jpg)
perlsub
$lines_left = 100;
sub read_line { die “trial period expired” unless $lines_left-- > 0; ...}
State Variables
![Page 56: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/56.jpg)
perlsub
my $lines_left = 100;
sub read_line { die “trial period expired” unless $lines_left-- > 0; ...}
State Variables
![Page 57: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/57.jpg)
perlsub
{ my $lines_left = 100;
sub read_line { die “trial period expired” unless $lines_left-- > 0; ... }}
State Variables
![Page 58: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/58.jpg)
perlsub
package Trial::Period;sub new { my ($class, $arg) = @_; my $guts = { lines_left => $arg->{lines}, error_msg => $arg->{error}, }; return bless $guts => $class;}
sub consume_line { my ($self) = @_; $self->{lines_left}--;}
sub lines_left { my ($self) = @_; return $self->{lines_left};}
sub assert_lines_left { my ($self) = @_; unless ($self->lines_left) { die $self->{error_msg}; }}1;
State Variables
my $LINES = 100;my $ERROR = “sorry, trial period over”;my $TRIAL = Trial::Period->new({ lines => $LINES, error => $ERROR,});
sub read_line { $TRIAL->assert_lines_left; ...}
![Page 59: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/59.jpg)
perlsub
{ my $lines_left = 100;
sub read_line { die “trial period expired” unless $lines_left-- > 0; ... }}
State Variables
![Page 60: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/60.jpg)
perlsub
sub read_line { state $lines_left = 100; die “trial period expired” unless $lines_left-- > 0; ...}
State Variables
![Page 61: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/61.jpg)
-x stacking
![Page 62: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/62.jpg)
perlfunc
if ( -f $fileand -w $fileand -z $file
) {unlink $file;
}
Stackable File Tests
![Page 63: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/63.jpg)
perlfunc
if ( -f $file and -w _ and -z _) {unlink $file;
}
Stackable File Tests
![Page 64: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/64.jpg)
perlfunc
if (-f -w -z $file) {unlink $file;
}
Stackable File Tests
![Page 65: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/65.jpg)
smart matching
![Page 66: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/66.jpg)
perlsyn
Smart Matching
![Page 67: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/67.jpg)
perlsyn
Smart Matching
- a new kind of comparison operator
![Page 68: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/68.jpg)
perlsyn
Smart Matching
- a new kind of comparison operator
- its behavior depends on its inputs
![Page 69: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/69.jpg)
perlsyn
Smart Matching
- a new kind of comparison operator
- its behavior depends on its inputs
- “if these two things match...”
![Page 70: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/70.jpg)
perlsyn
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...
![Page 71: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/71.jpg)
perlsyn
Smart Matching
![Page 72: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/72.jpg)
perlsyn
Smart Matching
if ($foo ~~ undef) { ... }
![Page 73: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/73.jpg)
perlsyn
Smart Matching
if ($foo ~~ undef) { ... }elsif ($foo ~~ @array) { ... }
![Page 74: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/74.jpg)
perlsyn
Smart Matching
if ($foo ~~ undef) { ... }elsif ($foo ~~ @array) { ... }elsif ($foo ~~ $code) { ... }
![Page 75: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/75.jpg)
perlsyn
Smart Matching
if ($foo ~~ undef) { ... }elsif ($foo ~~ @array) { ... }elsif ($foo ~~ $code) { ... }elsif ($foo ~~ %hash) { ... }
![Page 76: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/76.jpg)
perlsyn
Smart Matching
if ($foo ~~ undef) { ... }elsif ($foo ~~ @array) { ... }elsif ($foo ~~ $code) { ... }elsif ($foo ~~ %hash) { ... }elsif ($foo ~~ qr/re/) { ... }
![Page 77: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/77.jpg)
perlsyn
Smart Matching
if ($foo ~~ undef) { ... }elsif ($foo ~~ @array) { ... }elsif ($foo ~~ $code) { ... }elsif ($foo ~~ %hash) { ... }elsif ($foo ~~ qr/re/) { ... }elsif ($foo ~~ $bar) { ... }
![Page 78: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/78.jpg)
perlsyn
Smart Matching
if ($foo ~~ undef) { ... }elsif ($foo ~~ @array) { ... }elsif ($foo ~~ $code) { ... }elsif ($foo ~~ %hash) { ... }elsif ($foo ~~ qr/re/) { ... }elsif ($foo ~~ $bar) { ... }else { ... }
![Page 79: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/79.jpg)
perlsyn
Smart Matchinggiven ($foo) { when (undef) { ... } when (@array) { ... } when ($code) { ... } when (%hash) { ... } when (qr/re/) { ... } when ($bar) { ... } default { ... }}
![Page 80: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/80.jpg)
perlsyn
Smart Matching
if ($foo ~~ undef) { ... }elsif ($foo ~~ @array) { ... }elsif ($foo ~~ $code) { ... }elsif ($foo ~~ %hash) { ... }elsif ($foo ~~ qr/re/) { ... }elsif ($foo ~~ $bar) { ... }else { ... }
![Page 81: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/81.jpg)
perlsyn
Smart Matching
if ($foo ~~ undef) { ... }elsif ($foo ~~ $array) { ... }elsif ($foo ~~ $code) { ... }elsif ($foo ~~ $hash) { ... }elsif ($foo ~~ qr/re/) { ... }elsif ($foo ~~ $bar) { ... }else { ... }
![Page 82: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/82.jpg)
perlsyn
Smart Matching
my $test;
![Page 83: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/83.jpg)
perlsyn
Smart Matchinggiven ($foo) { when (undef) { ... } when ($aref) { ... } when ($code) { ... } when ($href) { ... } when ($regex) { ... } when ($object) { ... } default { ... }}
![Page 84: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/84.jpg)
perlsyn
Smart Matchinggiven ($foo) { when ($test_1) { ... } when ($test_2) { ... } when ($test_3) { ... } when ($test_4) { ... } when ($test_5) { ... } when ($test_6) { ... } default { ... }}
![Page 85: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/85.jpg)
perlsyn
Smart Matching
![Page 86: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/86.jpg)
perlsyn
Smart Matching
@want = @have->where($test)
![Page 87: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/87.jpg)
perlsyn
Smart Matching
@want = @have->where($test)
@want = @have->where(sub{ …… })
![Page 88: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/88.jpg)
perlsyn
Smart Matching
@want = @have->where($test)
@want = @have->where(sub{ …… })
@want = @have->where(qr/.../sm)
![Page 89: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/89.jpg)
perlsyn
Smart Matching
@want = @have->where($test)
@want = @have->where(sub{ …… })
@want = @have->where(qr/.../sm)
@want = @have->where([ 1,2,3 ])
![Page 90: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/90.jpg)
perlsyn
Smart Matching
![Page 91: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/91.jpg)
perlsyn
Smart Matchingsub where {
![Page 92: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/92.jpg)
perlsyn
Smart Matchingsub where { my ($array, $test) = @_;
![Page 93: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/93.jpg)
perlsyn
Smart Matchingsub where { my ($array, $test) = @_;
if (ref $test eq ‘ARRAY’) {
![Page 94: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/94.jpg)
perlsyn
Smart Matchingsub where { my ($array, $test) = @_;
if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test;
![Page 95: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/95.jpg)
perlsyn
Smart Matchingsub where { my ($array, $test) = @_;
if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array;
![Page 96: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/96.jpg)
perlsyn
Smart Matchingsub where { my ($array, $test) = @_;
if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; }
![Page 97: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/97.jpg)
perlsyn
Smart Matchingsub where { my ($array, $test) = @_;
if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) {
![Page 98: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/98.jpg)
perlsyn
Smart Matchingsub 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;
![Page 99: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/99.jpg)
perlsyn
Smart Matchingsub 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; }
![Page 100: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/100.jpg)
perlsyn
Smart Matchingsub 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’) {
![Page 101: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/101.jpg)
perlsyn
Smart Matchingsub 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;
![Page 102: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/102.jpg)
perlsyn
Smart Matchingsub 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; }
![Page 103: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/103.jpg)
perlsyn
Smart Matchingsub 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”
![Page 104: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/104.jpg)
perlsyn
Smart Matchingsub 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”}
![Page 105: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/105.jpg)
perlsyn
Smart Matching
sub where { my ($array, $test) = @_; grep { $_ ~~ $test } @$array;}
![Page 106: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/106.jpg)
perlsyn
Smart Matching
SmartMatch::Sugar
![Page 107: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/107.jpg)
perlsyn
Smart Matching
@want = @have->where( hash )
SmartMatch::Sugar
![Page 108: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/108.jpg)
perlsyn
Smart Matching
@want = @have->where( hash )
@want = @have->where( class )
SmartMatch::Sugar
![Page 109: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/109.jpg)
perlsyn
Smart Matching
@want = @have->where( hash )
@want = @have->where( class )
@want = @have->where(isa(‘Foo’))
SmartMatch::Sugar
![Page 110: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/110.jpg)
unknown undefined
![Page 111: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/111.jpg)
perldiag
$str = “Greetings, $name. Your last login was $last. It is now $time.”;
Better Error Message(s)
![Page 112: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/112.jpg)
perldiag
$str = “Greetings, $name. Your last login was $last. It is now $time.”;
Better Error Message(s)
Use of uninitialized value in concatenation (.) or string at hello.plx line 9.
![Page 113: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/113.jpg)
perldiag
Better Error Message(s)
Use of uninitialized value $time in concatenation (.) or string at hello.plx line 9.
$str = “Greetings, $name. Your last login was $last. It is now $time.”;
![Page 114: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/114.jpg)
inside-out objects
![Page 115: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/115.jpg)
Hash::Util::FieldHash
Inside-Out Objects
![Page 116: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/116.jpg)
Hash::Util::FieldHash
Inside-Out Objects
- traditional objects are a hashref
![Page 117: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/117.jpg)
Hash::Util::FieldHash
Inside-Out Objects
- traditional objects are a hashref
- look up attrs in the obj itself by attr name
![Page 118: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/118.jpg)
Hash::Util::FieldHash
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
![Page 119: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/119.jpg)
Hash::Util::FieldHash
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
![Page 120: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/120.jpg)
Hash::Util::FieldHash
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
![Page 121: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/121.jpg)
Hash::Util::FieldHash
Inside-Out Objects
sub size { my $self = shift;
if (@_) { return $self->{size} = shift; } else { return $self->{size}; }}
![Page 122: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/122.jpg)
Hash::Util::FieldHash
Inside-Out Objectsmy %size;sub size { my $self = shift;
if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; }}
![Page 123: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/123.jpg)
Hash::Util::FieldHash
Inside-Out Objectsmy %size;sub size { my $self = shift; my $id = refaddr $self;
if (@_) { return $size{ $id } = shift; } else { return $size{ $id }; }}
![Page 124: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/124.jpg)
Hash::Util::FieldHash
Inside-Out Objectsmy %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 };}
![Page 125: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/125.jpg)
Hash::Util::FieldHash
Inside-Out Objectsmy %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 };}
sub CLONE { my $class = shift;
my @properties = map { values %$_ } values %PROP_DATA_FOR;
for my $old_id ( keys %OBJ ) {
my $object = $OBJ{ $old_id }; my $new_id = refaddr $object;
for my $prop ( @properties ) { next unless exists $prop->{ $old }; $prop->{ $new } = $prop->{ $old }; delete $prop->{ $old }; }
weaken ( $OBJ{ $new } = $object ); delete $OBJ{ $old }; }}
![Page 126: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/126.jpg)
Hash::Util::FieldHash
Inside-Out Objectsmy %OBJECT_REGISTRY;my %size;sub size { my $self = shift; my $id = refaddr $self;
$self->register_object;
if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; }}
sub DESTROY { my $id = refaddr $_[0]; delete $size{ $id }; delete $OBJECT_REGISTRY{ $id };}
sub register_object { my ($self) = @_; my $id = refaddr $self; $OBJECT_REGISTRY{ $id } = $self;}
sub CLONE { my $class = shift;
my @properties = map { values %$_ } values %PROP_DATA_FOR;
for my $old_id ( keys %OBJECT_REGISTRY ) {
my $object = $OBJECT_REGISTRY{ $old_id }; my $new_id = refaddr $object;
for my $prop ( @properties ) { next unless exists $prop->{ $old_id }; $prop->{ $new_id } = $prop->{ $old_id }; delete $prop->{ $old_id }; }
weaken ( $OBJECT_REGISTRY{ $new_id } = $object ); delete $OBJECT_REGISTRY{ $old_id }; }}
![Page 127: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/127.jpg)
Hash::Util::FieldHash
Field Hashes
![Page 128: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/128.jpg)
Hash::Util::FieldHash
Field Hashes
- they’re just like hashes
![Page 129: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/129.jpg)
Hash::Util::FieldHash
Field Hashes
- they’re just like hashes
- objects as keys become object ids
![Page 130: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/130.jpg)
Hash::Util::FieldHash
Field Hashes
- they’re just like hashes
- objects as keys become object ids
- but get destroyed and cloned
![Page 131: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/131.jpg)
Hash::Util::FieldHash
Field Hashesmy %size;sub size { my $self = shift;
if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; }}
![Page 132: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/132.jpg)
Hash::Util::FieldHash
Field Hashesfieldhash my %size;sub size { my $self = shift;
if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; }}
![Page 133: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/133.jpg)
Hash::Util::FieldHash
Field Hashes{ fieldhash my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } }}
![Page 134: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/134.jpg)
Hash::Util::FieldHash
Field Hashessub size { my $self = shift; fieldhash state %size;
if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; }}
![Page 135: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/135.jpg)
lexical topic
![Page 136: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/136.jpg)
(topic is how you say $_)
![Page 137: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/137.jpg)
perlvar
for (@lines) { chomp; next if /^#/; next unless length; s/a/b/; sanity_check; say;}
Lexical Topic
![Page 138: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/138.jpg)
perlvar
Lexical Topic
for my $line (@lines) { chomp $line; next if $line ~~ /^#/; next unless length $line; $line =~ s/a/b/; sanity_check($line); say $line;}
![Page 139: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/139.jpg)
perlvar
for my $_ (@lines) { chomp; next if /^#/; next unless length; s/a/b/; sanity_check; say;}
Lexical Topic
![Page 140: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/140.jpg)
Regex
![Page 141: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/141.jpg)
named captures
![Page 142: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/142.jpg)
perlre
Regex: Named Captures
![Page 143: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/143.jpg)
perlre
Regex: Named Captures
- find matches by name, not position
![Page 144: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/144.jpg)
perlre
Regex: Named Captures
- find matches by name, not position
- avoid the dreaded $1
![Page 145: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/145.jpg)
perlre
Regex: Named Captures
- find matches by name, not position
- avoid the dreaded $1
- no longer second to Python or .Net!
![Page 146: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/146.jpg)
perlre
# our hypothetical format
section:property = value
Regex: Named Captures
![Page 147: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/147.jpg)
perlre
$line ~~ /(\w+):(\w+) = (\w+)/;
$name = $2;$value = $3;
Regex: Named Captures
![Page 148: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/148.jpg)
perlre
$lhs_re = qr/(\w+):(\w+)/;$rhs_re = qr/(\w+)/;
$line ~~ /$lhs_re = $rhs_re/;
$name = $2;$value = $3;
Regex: Named Captures
![Page 149: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/149.jpg)
perlre
$line ~~ /$lhs_re = $rhs_re/;
$name = $2;$value = $3;
Regex: Named Captures
![Page 150: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/150.jpg)
perlre
$line ~~ /$lhs_re = $rhs_re/;
$name = $+{ name }; $value = $+{ value };
Regex: Named Captures
![Page 151: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/151.jpg)
perlre
$lhs_re = qr/(\w+):(\w+)/;$rhs_re = qr/(\w+)/;
Regex: Named Captures
![Page 152: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/152.jpg)
perlre
$lhs_re = qr/(\w+):(?<name>\w+)/;$rhs_re = qr/(?<value>\w+)/;
Regex: Named Captures
![Page 153: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/153.jpg)
better backrefs
![Page 154: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/154.jpg)
perlre
Regex: Backreference
m{< (\w+) > .+ < /\1 > }x
![Page 155: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/155.jpg)
perlre
Regex: Backreference
m{< (\w+) > .+ < /\1 > }x
![Page 156: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/156.jpg)
perlre
Regex: Backreference
\10
![Page 157: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/157.jpg)
perlre
Regex: Backreference
qr{(\d)\10}
![Page 158: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/158.jpg)
perlre
Regex: Backreference
qr{ (\d) \1 0}x
![Page 159: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/159.jpg)
perlre
Regex: Backreference
m{< (\w+) > .+ < /\1 > }x
![Page 160: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/160.jpg)
perlre
Regex: Backreference
m{< (\w+) > .+ < /\g{1} > }x
![Page 161: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/161.jpg)
perlre
Regex: Backreference
\10
![Page 162: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/162.jpg)
perlre
Regex: Backreference
\g{10}
![Page 163: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/163.jpg)
perlre
Regex: Backreference
qr{(\d)\10}
![Page 164: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/164.jpg)
perlre
Regex: Backreference
qr{(\d)\g{1}0}
![Page 165: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/165.jpg)
perlre
Regex: Backreference
qr{(\d)\g{-1}0}
![Page 166: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/166.jpg)
perlre
Regex: Backreference
qr{ (?<digit>\d) \g{digit} 0}x
![Page 167: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/167.jpg)
wtf
Regex: Exit Strategymy $wtf_re = qr{xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:(?:[^(\040)<>@,;:”.\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:”.\\\[\]\000-\037\x80-\xff])|”[^\\\x80-\xff\n\015“]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015”]*)*”)[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:”.\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:”.\\\[\]\000-\037\x80-\xff])|”[^\\\x80-\xff\n\015”]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015”]*)*”)[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:”.\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:”.\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\04};
![Page 168: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/168.jpg)
perlop
Regex: Backreference
if ($str =~ $wtf_re) { ...}
![Page 169: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/169.jpg)
perlop
Regex: Backreference
if ($str ~~ $wtf_re) { ...}
![Page 170: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/170.jpg)
lexically scoped alternate trie-based reentrant user-defined regex pragmata
![Page 171: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/171.jpg)
flexible regex
![Page 172: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/172.jpg)
perlreapi
Alternate Regex Engines
![Page 173: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/173.jpg)
perlreapi
Alternate Regex Engines
- lets you change how regex work
![Page 174: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/174.jpg)
perlreapi
Alternate Regex Engines
- lets you change how regex work
- but not how you use them (=~, s///, etc)
![Page 175: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/175.jpg)
re::engine::POSIX
Alternate Regex Engines
![Page 176: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/176.jpg)
re::engine::POSIX
Alternate Regex Engines
egrep -r -l PATTERN DIR
![Page 177: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/177.jpg)
re::engine::POSIX
Alternate Regex Engines
my $regex = qr{ ... };
my @files = $find->file->in( $root );
say for grep { slurp ~~ $re } @files;
![Page 178: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/178.jpg)
re::engine::POSIX
Alternate Regex Engines
![Page 179: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/179.jpg)
re::engine::POSIX
Alternate Regex Engines
egrep -r -l ‘.+?’ DIR
![Page 180: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/180.jpg)
re::engine::POSIX
Alternate Regex Engines
my $regex = qr{ ... };
my @files = $find->file->in( $root );
say for grep { slurp ~~ $re } @files;
![Page 181: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/181.jpg)
re::engine::POSIX
Alternate Regex Engines
use re::engine::POSIX;
my $regex = qr{ ... };
my @files = $find->file->in( $root );
say for grep { slurp ~~ $re } @files;
![Page 182: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/182.jpg)
re::engine::POSIX
Alternate Regex Engines
use re::engine::POSIX;
my $regex = qr{ ... }x;
my @files = $find->file->in( $root );
say for grep { slurp ~~ $re } @files;
![Page 183: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/183.jpg)
http://www.perl.org/get.html
![Page 184: Perl 5.10 for People Who Aren't Totally Insane](https://reader030.fdocuments.us/reader030/viewer/2022020105/55795a8ed8b42ab6648b4e0f/html5/thumbnails/184.jpg)
Any questions?