What's New in Perl? v5.10 - v5.16

214
Perl 5 what's new?

description

This talk describes the most likely-to-be-used features added to Perl 5 between v5.10 and v5.16, inclusive.

Transcript of What's New in Perl? v5.10 - v5.16

Page 1: What's New in Perl?  v5.10 - v5.16

Perl 5what's new?

Page 2: What's New in Perl?  v5.10 - v5.16

Perl 5.10for people who are not totally insane

Page 3: What's New in Perl?  v5.10 - v5.16

Perl 5.12for everyday use

Page 4: What's New in Perl?  v5.10 - v5.16

Perl 5.14for pragmatists

Page 5: What's New in Perl?  v5.10 - v5.16

Perl 5.16for the working programmer

Page 6: What's New in Perl?  v5.10 - v5.16

Lexical Semantics!

Page 7: What's New in Perl?  v5.10 - v5.16

use feature ‘say’;say “This is a test!”;

{ no feature ‘say’; say “This is fatal!”;}

Page 8: What's New in Perl?  v5.10 - v5.16

use 5.16.0;say “This is a test!”;

{ no feature ‘say’; say “This is fatal!”;}

Page 9: What's New in Perl?  v5.10 - v5.16

#!/usr/bin/perluse strict;use warnings;use 5.16.0; # use feature ‘:5.16’;

my $x = Reticulator->new;

$x->reticulate(@splines);

Page 10: What's New in Perl?  v5.10 - v5.16

#!/usr/bin/perluse strict;use warnings; # no feature;

my $x = Reticulator->new;

$x->reticulate(@splines);

Page 11: What's New in Perl?  v5.10 - v5.16

#!/usr/bin/perluse strict;use warnings; # use feature ‘:default’

my $x = Reticulator->new;

$x->reticulate(@splines);

Page 12: What's New in Perl?  v5.10 - v5.16

array_base: $[

Page 13: What's New in Perl?  v5.10 - v5.16

Cool New Features!

Page 14: What's New in Perl?  v5.10 - v5.16

perldiag

$str = “Greetings, $name. Your last login was $last. It is now $time.”;

Better Error Message(s)

Page 15: What's New in Perl?  v5.10 - v5.16

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 16: What's New in Perl?  v5.10 - v5.16

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 17: What's New in Perl?  v5.10 - v5.16

perlsub

my $LINES_READ = 0;

sub read_line { $LINES_READ++;

...}

State Variables

Page 18: What's New in Perl?  v5.10 - v5.16

perlsub

{ my $LINES_READ = 0;

sub read_line { $LINES_READ++;

... }}

State Variables

Page 19: What's New in Perl?  v5.10 - v5.16

perlsub

sub read_line { state $LINES_READ = 0;

$LINES_READ++; ...}

State Variables

Page 20: What's New in Perl?  v5.10 - v5.16

perlop

truth and definedness

Page 21: What's New in Perl?  v5.10 - v5.16

perlop

truth and definedness

sub record_sale {

Page 22: What's New in Perl?  v5.10 - v5.16

perlop

truth and definedness

sub record_sale { my ($product, $amount) = @_;

Page 23: What's New in Perl?  v5.10 - v5.16

perlop

truth and definedness

sub record_sale { my ($product, $amount) = @_;

my $price = $amount

Page 24: What's New in Perl?  v5.10 - v5.16

perlop

truth and definedness

sub record_sale { my ($product, $amount) = @_;

my $price = $amount || $product->price;

Page 25: What's New in Perl?  v5.10 - v5.16

perlop

truth and definedness

sub record_sale { my ($product, $amount) = @_;

my $price = $amount || $product->price;

...

Page 26: What's New in Perl?  v5.10 - v5.16

perlop

truth and definedness

sub record_sale { my ($product, $amount) = @_;

my $price = $amount || $product->price;

...}

Page 27: What's New in Perl?  v5.10 - v5.16

perlop

truth and definednesssub record_sale { my ($product, $amount) = @_;

$price = defined $amount ? $amount : $product->price;

...}

Page 28: What's New in Perl?  v5.10 - v5.16

perlop

truth and definedness

sub record_sale { my ($product, $amount) = @_;

my $price = $amount || $product->price;

...}

Page 29: What's New in Perl?  v5.10 - v5.16

perlop

truth and definedness

sub record_sale { my ($product, $amount) = @_;

my $price = $amount // $product->price;

...}

Page 30: What's New in Perl?  v5.10 - v5.16

perlop

the new OR operator

sub record_sale { my ($product, $amount) = @_;

$amount //= $product->cost;

...}

Page 31: What's New in Perl?  v5.10 - v5.16

perlfunc

- new built-in, say

- it’s like print

- but it adds a newline for you

say $what

Page 32: What's New in Perl?  v5.10 - v5.16

perlfunc

say $what

Page 33: What's New in Perl?  v5.10 - v5.16

perlfunc

say $what

print “Hello, world!\n”;

Page 34: What's New in Perl?  v5.10 - v5.16

perlfunc

say $what

print “Hello, world!\n”;

print “$message\n”;

Page 35: What's New in Perl?  v5.10 - v5.16

perlfunc

say $what

print “Hello, world!\n”;

print “$message\n”;

print “$_\n” for @lines;

Page 36: What's New in Perl?  v5.10 - v5.16

perlfunc

say $what

print “Hello, world!\n”;

print “$message\n”;

print “$_\n” for @lines;

say “Hello, world!”;

Page 37: What's New in Perl?  v5.10 - v5.16

perlfunc

say $what

print “Hello, world!\n”;

print “$message\n”;

print “$_\n” for @lines;

say “Hello, world!”;

say $message;

Page 38: What's New in Perl?  v5.10 - v5.16

perlfunc

say $what

print “Hello, world!\n”;

print “$message\n”;

print “$_\n” for @lines;

say “Hello, world!”;

say $message;

say for @lines;

Page 39: What's New in Perl?  v5.10 - v5.16
Page 40: What's New in Perl?  v5.10 - v5.16

$ perl -e ‘print “Foo\n”’

Page 41: What's New in Perl?  v5.10 - v5.16

$ perl -e ‘print “Foo\n”’

$ perl -E ‘say “Foo”’

Page 42: What's New in Perl?  v5.10 - v5.16

sub fact { my ($x) = @_; # must be +int return $x if $x == 1; return $x * fact($x - 1);}

Recursion!

Page 43: What's New in Perl?  v5.10 - v5.16

sub fact { my ($x) = @_; # must be +int return $x if $x == 1; return $x * fact($x - 1);}

Recursion!

Page 44: What's New in Perl?  v5.10 - v5.16

my $fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * $fact->($x - 1);};

Recursion!

Page 45: What's New in Perl?  v5.10 - v5.16

my $fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * $fact->($x - 1);};

Recursion!

Page 46: What's New in Perl?  v5.10 - v5.16

my $fact;$fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * $fact->($x - 1);};

Recursion!

Page 47: What's New in Perl?  v5.10 - v5.16

my $fact;$fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * $fact->($x - 1);};

Recursion!

Page 48: What's New in Perl?  v5.10 - v5.16

use Scalar::Util qw(weaken);my $fact = do { my $f1; my $f2 = $f1 = sub { my ($x) = @_; return $x if $x == 1; return $x * $f1->($x - 1); }; weaken($f1); $f1;};

Recursion!

Page 49: What's New in Perl?  v5.10 - v5.16

use 5.16.0; # current_sub

my $fact = sub { my ($x) = @_; # must be +int return $x if $x == 1; return $x * __SUB__->($x - 1);};

Recursion!

Page 50: What's New in Perl?  v5.10 - v5.16

Filehandles!

Page 51: What's New in Perl?  v5.10 - v5.16

autodie

autodie

open my $fh, ‘<‘, $filename;

while (<$fh>) { ...}

close $fh;

Page 52: What's New in Perl?  v5.10 - v5.16

autodie

autodie

open my $fh, ‘<‘, $filename or die “couldn’t open $filename: $!”;

while (<$fh>) { ...}

close $fh or die “couldn’t close $filename: $!”;

Page 53: What's New in Perl?  v5.10 - v5.16

autodie

autodie

use autodie;

open my $fh, ‘<‘, $filename;

while (<$fh>) { ...}

close $fh;

Page 54: What's New in Perl?  v5.10 - v5.16

autodie

autodie

use autodie;

open my $fh, ‘<‘, $filename;

while (<$fh>) { no autodie; rmdir or warn “couldn’t remove $_: $!”;}

close $fh;

Page 55: What's New in Perl?  v5.10 - v5.16

autodie

autodie

use autodie;

sub foo { my $filename = shift; open my $fh, ‘<‘, $filename;

while (<$fh>) { ... }} # this implicit close DID NOT AUTODIE

Page 56: What's New in Perl?  v5.10 - v5.16

perlopentut

IO::Filesub stream_to_fh { my ($self, $fh) = @_;

fileno $fh or die “can’t stream to closed fh”;

while (my $hunk = $self->next_hunk) { print {$fh} $hunk; }

close $fh or die “error closing: $!”;}

Page 57: What's New in Perl?  v5.10 - v5.16

perlopentut

IO::Filesub stream_to_fh { my ($self, $fh) = @_;

$fh->fileno or die “can’t stream to closed fh”;

while (my $hunk = $self->next_hunk) { $fh->print($hunk); }

$fh->close or die “error closing: $!”;}

Page 58: What's New in Perl?  v5.10 - v5.16

perlopentut

IO::File

sub stream_to_fh { ... $fh->print($hunk); ... $fh->close or die “error closing: $!”;}

open my $target, ‘>’, ‘/dev/null’ or die “can’t open bit bucket: $!”;

stream_to_fh($target);

Page 59: What's New in Perl?  v5.10 - v5.16

perlopentut

IO::Fileuse IO::File;

sub stream_to_fh { ... $fh->print($hunk); ... $fh->close or die “error closing: $!”;}

open my $target, ‘>’, ‘/dev/null’ or die “can’t open bit bucket: $!”;

stream_to_fh($target);

Page 60: What's New in Perl?  v5.10 - v5.16

perlopentut

IO::Fileuse 5.14.0;

sub stream_to_fh { ... $fh->print($hunk); ... $fh->close or die “error closing: $!”;}

open my $target, ‘>’, ‘/dev/null’ or die “can’t open bit bucket: $!”;

stream_to_fh($target);

Page 61: What's New in Perl?  v5.10 - v5.16

perlopentut

IO::Fileuse 5.14.0;use autodie;sub stream_to_fh { ... $fh->print($hunk); ... $fh->close or die “error closing: $!”;}

open my $target, ‘>’, ‘/dev/null’ or die “can’t open bit bucket: $!”;

stream_to_fh($target);

Page 62: What's New in Perl?  v5.10 - v5.16

perlfunc

Package Blocks

package Library::Awesome;our $VERSION = 1.234;

sub foo { ... }

1;

Page 63: What's New in Perl?  v5.10 - v5.16

perlfunc

Package Blocks

use 5.12.0;

package Library::Awesome 1.234;

sub foo { ... }

1;

Page 64: What's New in Perl?  v5.10 - v5.16

perlfunc

Package Blocks

use 5.12.0;

package Library::Awesome 1.234-alpha;

sub foo { ... }

1;

Page 65: What's New in Perl?  v5.10 - v5.16

perlfunc

Package Blocks

package Library::Awesome 1.234 {

sub foo { ... }

}

1;

Page 66: What's New in Perl?  v5.10 - v5.16

perldoc

overloading

- the -x overload

- the qr overload

- "no overloading"

- unknown overload warns

Page 67: What's New in Perl?  v5.10 - v5.16

Other New Features!

Page 68: What's New in Perl?  v5.10 - v5.16

smrt match

Page 69: What's New in Perl?  v5.10 - v5.16

if ($x ~~ $y) { ...}

smrt match

Page 70: What's New in Perl?  v5.10 - v5.16

perldoc

smrt match

Page 71: What's New in Perl?  v5.10 - v5.16

perldoc

smrt match

- if $x and $y are unknown, there are 23 possible dispatch paths

Page 72: What's New in Perl?  v5.10 - v5.16

perldoc

smrt match

- if $x and $y are unknown, there are 23 possible dispatch paths

- and some of them redispatch recursively

Page 73: What's New in Perl?  v5.10 - v5.16

perldoc

smrt match

- if $x and $y are unknown, there are 23 possible dispatch paths

- and some of them redispatch recursively

- no, you won't remember them all

Page 74: What's New in Perl?  v5.10 - v5.16

perldoc

smrt match

- if $x and $y are unknown, there are 23 possible dispatch paths

- and some of them redispatch recursively

- no, you won't remember them all

- ...and they can't be intuited

Page 75: What's New in Perl?  v5.10 - v5.16

Matching

Page 76: What's New in Perl?  v5.10 - v5.16

if ($x ~~ $y) {...}

Matching

Page 77: What's New in Perl?  v5.10 - v5.16

if ($x ~~ $y) {...}if ($str ~~ %hash) {...}

Matching

Page 78: What's New in Perl?  v5.10 - v5.16

if ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}

Matching

Page 79: What's New in Perl?  v5.10 - v5.16

if ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}if ($str ~~ [ \%h, ...]) {...}

Matching

Page 80: What's New in Perl?  v5.10 - v5.16

if ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}if ($str ~~ [ \%h, ...]) {...}if (%hash ~~ %h) {...}

Matching

Page 81: What's New in Perl?  v5.10 - v5.16

if ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}if ($str ~~ [ \%h, ...]) {...}if (%hash ~~ %h) {...}if (%hash ~~ @arr) {...}

Matching

Page 82: What's New in Perl?  v5.10 - v5.16

if ($x ~~ $y) {...}if ($str ~~ %hash) {...}if ($str ~~ @arr) {...}if ($str ~~ [ \%h, ...]) {...}if (%hash ~~ %h) {...}if (%hash ~~ @arr) {...}if (%hash ~~ [ \%h,...]) {...}

Matching

Page 83: What's New in Perl?  v5.10 - v5.16

given ($x) { when ($y) { ... } when ($z) { ... }}

Page 84: What's New in Perl?  v5.10 - v5.16

given ($x) { when ($y) { try { ... } catch { warn “error: $_”; return undef; } }}

Page 85: What's New in Perl?  v5.10 - v5.16

each @array

Page 86: What's New in Perl?  v5.10 - v5.16

while (my ($i, $v) = each @array) { say “$i: $v”;}

each @array

Page 87: What's New in Perl?  v5.10 - v5.16

push $aref, @etc;

Page 88: What's New in Perl?  v5.10 - v5.16

Now With Fewer Bugs!

Page 89: What's New in Perl?  v5.10 - v5.16

y2038

Page 90: What's New in Perl?  v5.10 - v5.16
Page 91: What's New in Perl?  v5.10 - v5.16

~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’

Page 92: What's New in Perl?  v5.10 - v5.16

~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038

Page 93: What's New in Perl?  v5.10 - v5.16

~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038

~$ perl5.10.0 -E ‘say scalar localtime 2**31’

Page 94: What's New in Perl?  v5.10 - v5.16

~$ perl5.10.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038

~$ perl5.10.0 -E ‘say scalar localtime 2**31’Fri Dec 13 15:45:52 1901

Page 95: What's New in Perl?  v5.10 - v5.16
Page 96: What's New in Perl?  v5.10 - v5.16

~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’

Page 97: What's New in Perl?  v5.10 - v5.16

~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038

Page 98: What's New in Perl?  v5.10 - v5.16

~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038

~$ perl5.12.0 -E ‘say scalar localtime 2**31’

Page 99: What's New in Perl?  v5.10 - v5.16

~$ perl5.12.0 -E ‘say scalar localtime 2**31-1’Mon Jan 18 22:14:07 2038

~$ perl5.12.0 -E ‘say scalar localtime 2**31’Mon Jan 18 22:14:08 2038

Page 100: What's New in Perl?  v5.10 - v5.16

perlvar

$@

Page 101: What's New in Perl?  v5.10 - v5.16

Try::Tiny

$@

Page 102: What's New in Perl?  v5.10 - v5.16

Try::Tiny

$@

- Well, actually, you use Try::Tiny, right?

Page 103: What's New in Perl?  v5.10 - v5.16

Try::Tiny

$@

- Well, actually, you use Try::Tiny, right?

- But this makes Try::Tiny more reliable, too!

Page 104: What's New in Perl?  v5.10 - v5.16

Try::Tiny

$@

- Well, actually, you use Try::Tiny, right?

- But this makes Try::Tiny more reliable, too!

- You see, eval and $@ are totally awful

Page 105: What's New in Perl?  v5.10 - v5.16

perlfunc

use 5.12.0;

{ package X; sub DESTROY { eval { } }}

eval { my $x = bless {} => ‘X’; die “DEATH!!”;};

warn “ERROR: $@”;

Page 106: What's New in Perl?  v5.10 - v5.16

perlfunc

use 5.12.0;

{ package X; sub DESTROY { eval { } }}

eval { my $x = bless {} => ‘X’; die “DEATH!!”;};

warn “ERROR: $@”;

$ perl5.12.4 test.plERROR:

Page 107: What's New in Perl?  v5.10 - v5.16

perlfunc

use 5.14.0;

{ package X; sub DESTROY { eval { } }}

eval { my $x = bless {} => ‘X’; die “DEATH!!”;};

warn “ERROR: $@”;

Page 108: What's New in Perl?  v5.10 - v5.16

perlfunc

use 5.14.0;

{ package X; sub DESTROY { eval { } }}

eval { my $x = bless {} => ‘X’; die “DEATH!!”;};

warn “ERROR: $@”;

$ perl5.14.1 test.plERROR: DEATH!!

Page 109: What's New in Perl?  v5.10 - v5.16
Page 110: What's New in Perl?  v5.10 - v5.16

perl -le ‘print $^X’

Page 111: What's New in Perl?  v5.10 - v5.16

perl -le ‘print $^X’

10.0: perl

Page 112: What's New in Perl?  v5.10 - v5.16

perl -le ‘print $^X’

10.0: perl10.1: perl

Page 113: What's New in Perl?  v5.10 - v5.16

perl -le ‘print $^X’

10.0: perl10.1: perl12.0: perl

Page 114: What's New in Perl?  v5.10 - v5.16

perl -le ‘print $^X’

10.0: perl10.1: perl12.0: perl14.0: perl

Page 115: What's New in Perl?  v5.10 - v5.16

perl -le ‘print $^X’

10.0: perl10.1: perl12.0: perl14.0: perl16.0: /Users/rjbs/perl5/perlbrew/perls/16.0/bin/perl

Page 116: What's New in Perl?  v5.10 - v5.16

Simpler Strings

Page 117: What's New in Perl?  v5.10 - v5.16

perlunicode

Perl is Good at Unicode

Page 118: What's New in Perl?  v5.10 - v5.16

perlunicode

Perl 5.16 is Better

Page 119: What's New in Perl?  v5.10 - v5.16

perlunicode

Perl 5.16 is Better

- Unicode 6.1

Page 120: What's New in Perl?  v5.10 - v5.16

perlunicode

Perl 5.16 is Better

- Unicode 6.1

- every character property is available

Page 121: What's New in Perl?  v5.10 - v5.16

perlunicode

Perl 5.16 is Better

- Unicode 6.1

- every character property is available

- \X in regex is more sensible

Page 122: What's New in Perl?  v5.10 - v5.16

perlunicode

“The Unicode Bug”

Page 123: What's New in Perl?  v5.10 - v5.16

perlunicode

“The Unicode Bug”

- strings aren’t always treated as Unicode

Page 124: What's New in Perl?  v5.10 - v5.16

perlunicode

“The Unicode Bug”

- strings aren’t always treated as Unicode

- this causes weird bugs that take ages to find

Page 125: What's New in Perl?  v5.10 - v5.16

perlunicode

“The Unicode Bug”

- strings aren’t always treated as Unicode

- this causes weird bugs that take ages to find

- use feature ‘unicode_strings’;

Page 126: What's New in Perl?  v5.10 - v5.16

perlunicode

“The Unicode Bug”

- strings aren’t always treated as Unicode

- this causes weird bugs that take ages to find

- use feature ‘unicode_strings’;

- or use 5.12.0

Page 127: What's New in Perl?  v5.10 - v5.16

perldoc

Unicode eval

- eval $str- is that octets or chars?

- what if it includes "use utf8"

- or you're under "use utf8"?

Page 128: What's New in Perl?  v5.10 - v5.16

perldoc

Unicode eval

- evalbytes $str- unicode_eval

Page 129: What's New in Perl?  v5.10 - v5.16

perldiag

My Favorite 5.12-ism?

if (length $input->{new_email}) { $user->update_email(...);}

Page 130: What's New in Perl?  v5.10 - v5.16

perldiag

My Favorite 5.12-ism?

Use of uninitialized value in length at - line 3120.

if (length $input->{new_email}) { $user->update_email(...);}

Page 131: What's New in Perl?  v5.10 - v5.16

perldiag

My Favorite 5.12-ism?

if (length $input->{new_email}) { $user->update_email(...);}

Page 132: What's New in Perl?  v5.10 - v5.16

perlsyn

say “I \o{23145} Perl 5.14!”;

Page 133: What's New in Perl?  v5.10 - v5.16

perlsyn

say “I \o{23145} Perl 5.14!”;

I ♥ Perl 5.14!

Page 134: What's New in Perl?  v5.10 - v5.16

perlsyn

say “I \23145 Perl 5.14!”;

I ?45 Perl 5.14!

Page 135: What's New in Perl?  v5.10 - v5.16

perlsyn

say “I \023145 Perl 5.14!”;

I 145 Perl 5.14!

Page 136: What's New in Perl?  v5.10 - v5.16

perlre

qr{ (1) (2) (3) (4) \7 \10 (5) (6) (7) (8) (9) \7 \10 (10) \7 \10}x;

Page 137: What's New in Perl?  v5.10 - v5.16

perlre

qr{ (1) (2) (3) (4) \o{7} \o{10} (5) (6) (7) (8) (9) \o{7} \o{10} (10) \g{7} \g{10}}x;

Page 138: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6.1

Page 139: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6.1

Page 140: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6

Page 141: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6

Page 142: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6

Page 143: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6

Page 144: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6

Page 145: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6

Page 146: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6

Page 147: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6

Page 148: What's New in Perl?  v5.10 - v5.16

charnames

Unicode 6

Page 149: What's New in Perl?  v5.10 - v5.16

use 5.16.0;

say “I \N{HEAVY BLACK HEART} Queensr” . “\N{LATIN SMALL LETTER Y WITH DIAERESIS}” . “che!”;

\N{...}

Page 150: What's New in Perl?  v5.10 - v5.16

case folding

Page 151: What's New in Perl?  v5.10 - v5.16

if (lc $foo eq lc $bar) { ...}

Case Folding

Page 152: What's New in Perl?  v5.10 - v5.16

if (fc $foo eq fc $bar) { ...}

Case Folding

Page 153: What's New in Perl?  v5.10 - v5.16

Case Folding

Page 154: What's New in Perl?  v5.10 - v5.16

lc ‘ς‘ ➔ ‘ς‘

Case Folding

Page 155: What's New in Perl?  v5.10 - v5.16

lc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘

Case Folding

Page 156: What's New in Perl?  v5.10 - v5.16

lc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘

Case Folding

Page 157: What's New in Perl?  v5.10 - v5.16

lc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘

lc ‘ß’ ➔ ‘ß’

Case Folding

Page 158: What's New in Perl?  v5.10 - v5.16

lc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘

lc ‘ß’ ➔ ‘ß’uc ‘ß’ ➔ ‘SS’

Case Folding

Page 159: What's New in Perl?  v5.10 - v5.16

lc ‘ς‘ ➔ ‘ς‘uc ‘ς‘ ➔ ‘Σ‘fc ‘ς‘ ➔ ‘σ‘

lc ‘ß’ ➔ ‘ß’uc ‘ß’ ➔ ‘SS’fc ‘ß’ ➔ ‘ss’

Case Folding

Page 160: What's New in Perl?  v5.10 - v5.16

Case Folding

Page 161: What's New in Perl?  v5.10 - v5.16

“file under: \L$name”

Case Folding

Page 162: What's New in Perl?  v5.10 - v5.16

“file under: \L$name”

“file under: \F$name”

Case Folding

Page 163: What's New in Perl?  v5.10 - v5.16

Better Regex

Page 164: What's New in Perl?  v5.10 - v5.16

named captures

Page 165: What's New in Perl?  v5.10 - v5.16

perlre

Regex: Named Captures

Page 166: What's New in Perl?  v5.10 - v5.16

perlre

Regex: Named Captures

- find matches by name, not position

Page 167: What's New in Perl?  v5.10 - v5.16

perlre

Regex: Named Captures

- find matches by name, not position

- avoid the dreaded $1

Page 168: What's New in Perl?  v5.10 - v5.16

perlre

Regex: Named Captures

- find matches by name, not position

- avoid the dreaded $1

- no longer second to Python or .Net!

Page 169: What's New in Perl?  v5.10 - v5.16

perlre

# our hypothetical format

section:property = value

Regex: Named Captures

Page 170: What's New in Perl?  v5.10 - v5.16

perlre

$line =~ /(\w+):(\w+) = (\w+)/;

$section = $1$name = $2;$value = $3;

Regex: Named Captures

Page 171: What's New in Perl?  v5.10 - v5.16

perlre

Regex: Named Captures$line =~ / (?<section> \w+): (?<name> \w+) \s* = \s* (?<value> \w+)/x;

$section = $+{section};$name = $+{name};$value = $+{value};

Page 172: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

my $hostname = get_hostname;

$hostname =~ s/\..*//;

Page 173: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

my $hostname = get_hostname =~ s/\..*//;

Page 174: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

(my $hostname = get_hostname) =~ s/\..*//;

Page 175: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

my $hostname = get_hostname =~ s/\..*//r;

Page 176: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

my @short_names = map { s/\..*//; } @long_names;

Page 177: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

my @short_names = map { s/\..*//; $_ } @long_names;

Page 178: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

my @short_names = map { my $x = $_; $x =~ s/\..*//; $x } @long_names;

Page 179: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

my @short_names = map { s/\..*//r } @long_names;

Page 180: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

my @short_names = map s/\..*//r, @long_names;

Page 181: What's New in Perl?  v5.10 - v5.16

perldoc

New Regex Modifiers

Page 182: What's New in Perl?  v5.10 - v5.16

perldoc

/u /a /aa /d /l

"൮" =~ /\d/ ✓ ! ! ¿? ¿?

"ð" =~ /\w/ ✓ ! ! ¿? ¿?

"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?

"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿?

New Regex Modifiers

Page 183: What's New in Perl?  v5.10 - v5.16

perldoc

/u /a /aa /d /l

"൮" =~ /\d/ ✓ ! ! ¿? ¿?

"ð" =~ /\w/ ✓ ! ! ¿? ¿?

"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?

"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿?

New Regex Modifiers

Page 184: What's New in Perl?  v5.10 - v5.16

perldoc

/u /a /aa /d /l

"൮" =~ /\d/ ✓ ! ! ¿? ¿?

"ð" =~ /\w/ ✓ ! ! ¿? ¿?

"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?

"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿?

New Regex Modifiers

Page 185: What's New in Perl?  v5.10 - v5.16

perldoc

/u /a /aa /d /l

"൮" =~ /\d/ ✓ ! ! ¿? ¿?

"ð" =~ /\w/ ✓ ! ! ¿? ¿?

"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?

"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿?

New Regex Modifiers

Page 186: What's New in Perl?  v5.10 - v5.16

perldoc

/u /a /aa /d /l

"൮" =~ /\d/ ✓ ! ! ¿? ¿?

"ð" =~ /\w/ ✓ ! ! ¿? ¿?

"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?

"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿?

New Regex Modifiers

Page 187: What's New in Perl?  v5.10 - v5.16

perldoc

/u /a /aa /d /l

"൮" =~ /\d/ ✓ ! ! ¿? ¿?

"ð" =~ /\w/ ✓ ! ! ¿? ¿?

"ff" =~ /ff/i ✓ ✓ ! ¿? ¿?

"ff" =~ /pL/i ✓ ✓ ✓ ¿? ¿?

New Regex Modifiers

Page 188: What's New in Perl?  v5.10 - v5.16

perlre

New Regex Modifiers

# To be really ASCII-only:

die “funny un-American characters” if $str =~ /\P{ASCII}/;

$str =~ /...actual pattern.../;

Page 189: What's New in Perl?  v5.10 - v5.16

study

Page 190: What's New in Perl?  v5.10 - v5.16

my $re = qr{...complex...};

study

Page 191: What's New in Perl?  v5.10 - v5.16

my $re = qr{...complex...};my $str = q{...long complex...};

study

Page 192: What's New in Perl?  v5.10 - v5.16

my $re = qr{...complex...};my $str = q{...long complex...};

$str =~ $re; # slow!!

study

Page 193: What's New in Perl?  v5.10 - v5.16

my $re = qr{...complex...};my $str = q{...long complex...};

$str =~ $re; # slow!!

study $str; # does stuff

study

Page 194: What's New in Perl?  v5.10 - v5.16

my $re = qr{...complex...};my $str = q{...long complex...};

$str =~ $re; # slow!!

study $str; # does stuff

$str =~ $re; # fast!!

study

Page 195: What's New in Perl?  v5.10 - v5.16

my $re = qr{...complex...};my $str = q{...long complex...};

$str =~ $re; # slow but right!!

study $str; # does stuff

$str =~ $re; # who knows!!

study

Page 196: What's New in Perl?  v5.10 - v5.16

my $re = qr{...complex...};my $str = q{...long complex...};

$str =~ $re; # slow but right!!

study $str; # does nothing

$str =~ $re; # slow but right!!

study

Page 197: What's New in Perl?  v5.10 - v5.16

Modder Modlib

Page 198: What's New in Perl?  v5.10 - v5.16

perlmodlib

Newly Cored Librarys

- JSON

- HTTP::Tiny

- Module::Metadata

- CPAN::Meta

Page 199: What's New in Perl?  v5.10 - v5.16

perlmodlib

Newly Ejected Librarys

- Devel::DProf

- Switch

- the perl4 core

- ...and more

Page 200: What's New in Perl?  v5.10 - v5.16

Old Stuff Removed

Page 201: What's New in Perl?  v5.10 - v5.16

perlop

qw()

for my $show qw(Smallville Lost V) { $tivo->cancel_pass( $show );}

Page 202: What's New in Perl?  v5.10 - v5.16

perlop

qw()

for my $show (qw(Smallville Lost V)) { $tivo->cancel_pass( $show );}

Page 203: What's New in Perl?  v5.10 - v5.16

$[

Page 204: What's New in Perl?  v5.10 - v5.16

perlvar

$[ - first index of array

Page 205: What's New in Perl?  v5.10 - v5.16

perlvar

$[ - first index of array

- so you can make $array[1] mean first

Page 206: What's New in Perl?  v5.10 - v5.16

perlvar

$[ - first index of array

- so you can make $array[1] mean first

- isn’t that awesome???

Page 207: What's New in Perl?  v5.10 - v5.16

perlvar

$[ - first index of array

- so you can make $array[1] mean first

- isn’t that awesome???

- yeah, about as awesome as Comic Sans

Page 208: What's New in Perl?  v5.10 - v5.16

perlvar

$[

$[ = 1;

for (1 .. $#array) { ...}

Page 209: What's New in Perl?  v5.10 - v5.16

perlvar

$[

for ($[ .. $#array) { ...}

Page 210: What's New in Perl?  v5.10 - v5.16

perlvar

$[

Assigned to $[. Are you some kind of idiot or something? at -e line 123.

Page 211: What's New in Perl?  v5.10 - v5.16

perlvar

$[

Use of assignment to $[ is deprecated at -e line 123.

Page 212: What's New in Perl?  v5.10 - v5.16

defined @arr

Page 213: What's New in Perl?  v5.10 - v5.16

Any questions?

Page 214: What's New in Perl?  v5.10 - v5.16

Thank you!