SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
9.
Optimise programmer time <ul><li>Most advanced programming language ever! </li></ul><ul><li>Perl: print “hello” </li></ul><ul><li>Perl 6: say “hello” </li></ul><ul><li>Perl 5.10: say “hello” </li></ul>
10.
Save typing <ul><li>My poor fingers! </li></ul><ul><li>Also none of this nasty quoting business </li></ul><ul><li>This might seem like it's trivial... </li></ul>
11.
Or <ul><li>$c = $a | | $b is handy </li></ul><ul><li>confused by empty string, undef or zero </li></ul>
12.
Defined or <ul><li>$c = $a // $b is handier </li></ul><ul><li>same as $c = defined($a) ? $a : $b </li></ul>
13.
dor and err <ul><li>There's also low-precedence // </li></ul><ul><li>use feature qw(dor err); </li></ul><ul><li>fileno($x) dor die 'That's not a filehandle'; </li></ul><ul><li>fileno($x) err die 'That's not a filehandle'; </li></ul>
14.
State variables <ul><li>The old way of having a persistent variable: </li></ul><ul><li>{ my $i = 0; sub incrementor { return $i++; } } </li></ul>
15.
State variables <ul><li>use feature 'state'; sub incrementor { state $i = 0; return $i++; } </li></ul>
16.
Local caches <ul><li>State variables can live deep inside subroutines... </li></ul><ul><li>for my $x (...) { for my $y (...) { state %seen; next if $seen{$x}{$y}++; } } </li></ul>
17.
Switch <ul><li>Perl 5.10 introduces a native switch statement. </li></ul><ul><li>Similar to Perl 6's switch, and Switch.pm (source filter) </li></ul><ul><li>Built into the Perl interpreter </li></ul>
18.
Guessing Game <ul><li>use feature qw(switch say); my @guessed; my $num = int(rand 100)+1; while (my $guess = <STDIN>) { chomp $guess; given($guess) { when (//) { say "Give me an integer" } when (@guessed) { say "You've tried that" } when ($num) { say "Just right!"; last } when ($_ < $num) { say "Too low"; continue } when ($_ > $num) { say "Too high"; continue } push(@guessed,$_); } } </li></ul>
19.
foreach / when <ul><li>use feature 'switch'; foreach (@cool_things) { when (/pirate/) { $pirate++ } when (/ninja/) { $ninja++ } when (/robot/) { $robot++ } say "$_ doesn't look cool..."; } </li></ul><ul><li>when automatically calls next at the end of its block </li></ul>
20.
Smart-match <ul><li>use feature '~~'; if ($x ~~ @array) { say "$x exists" } if ($x ~~ /ninja/) { say "Ninja in string"} if (@x ~~ /ninja/) { say "Ninja in array" } if ($key ~~ %hash) { say "$key exists" } if ($subref ~~ $arg) { say 'sub($arg) true' } </li></ul>
21.
Smart-match <ul><li>use feature '~~'; if (@array ~~ $x) { say "$x exists" } if (/ninja/ ~~ $x) { say "Ninja in string"} if (/ninja/ ~~ @x) { say "Ninja in array" } if (%hash ~~ $key) { say "$key exists" } if ($arg ~~ $subref) { say 'sub($arg) true' } </li></ul><ul><li>~~ can be overloaded </li></ul>
22.
UNIVERSAL::DOES <ul><li>Traditionally isa would be used to determine the capabilities of a class: </li></ul><ul><li>provides a way to show compatibility, without inheritance </li></ul><ul><li>$obj‐>isa('Logger'); </li></ul><ul><li>$obj‐>DOES('Logger'); </li></ul>
23.
Helicopter <ul><li>package Helicopter; sub DOES { my ($this, $interface) = @_; return 1 if ($interface eq "Airplane"); return $this->SUPER::does($interface); } </li></ul>
24.
Constant (un-)folding <ul><li>Perl 'folds' constants at compile time </li></ul><ul><li>9+5 gets converted to 14 </li></ul><ul><li>In Perl 5.10, exceptional constants are unfolded </li></ul><ul><li>They'll still throw run-time exceptions if you try to execute them </li></ul>
25.
Hash::Util::FieldHash <ul><li>5.10 comes with support for Field Hashes, which: </li></ul><ul><ul><li>Can use references as hash keys </li></ul></ul><ul><ul><li>Reference-keys migrate correctly across threads </li></ul></ul><ul><ul><li>Entries to stale references are automatically deleted </li></ul></ul><ul><li>(Inside-Out objects work nicely) </li></ul>
26.
Assertions <ul><li>Perl 5.10 implements real assertions </li></ul><ul><li>Normally compiled away </li></ul><ul><li>Can be enabled on a per-module basis </li></ul><ul><li># This is normally compiled away sub assert_sanity :assertion {...} # Enable assertions for MyModule perl -A=MyModule prog.pl </li></ul>
27.
User-defined lexical pragmata <ul><li>We've used lexical pragmata for years: { use strict; ... } </li></ul><ul><li>In Perl 5.10 you can write your own! </li></ul><ul><li>%^H allows "hints" to be attached to the optree </li></ul><ul><li>use feature is implemented this way </li></ul>
28.
More modules <ul><li>encoding::warnings </li></ul><ul><li>Math::BigInt::FastCalc </li></ul><ul><li>Time::Piece </li></ul><ul><li>Win32API::File </li></ul><ul><li>CPANPLUS </li></ul>
29.
CPANPLUS <ul><li>Hi Jos! </li></ul><ul><li>It's about time, isn't it? </li></ul><ul><li>Means we have many other modules in the core... </li></ul>
31.
Other goodies <ul><li>Misc Attribute Decoration </li></ul><ul><li>$AUTOLOAD can be tainted </li></ul><ul><li>Source filters in @INC </li></ul><ul><li>encodings::warnings is lexical </li></ul><ul><li>Better threads </li></ul><ul><li>Faster UTF-8 </li></ul>
32.
More other goodies <ul><li>Faster stat() on Windows </li></ul><ul><li>Relocatable installs </li></ul><ul><li>Overloading for re-blessed objects </li></ul><ul><li>Better Windows support </li></ul><ul><li>Smaller memory footprint (slightly faster) </li></ul><ul><li>More documentation </li></ul>
33.
More details? <ul><li>http://search.cpan.org/dist/perl/pod/perl594delta.pod </li></ul>
35.
When will it be out? <ul><li>Stable: 5.8.9 “by April 1st” </li></ul><ul><li>New: 5.10 “after lunch, before Christmas” </li></ul><ul><li>New new: 6.0.0 “after lunch, before Christmas” </li></ul>
37.
License <ul><li>These slides are Copyright 2006 Paul Fenwick, Audrey Tang, Leon Brocard </li></ul><ul><li>The text may be distributed under your choice of any of the following: </li></ul><ul><ul><li>The license terms of Perl itself </li></ul></ul><ul><ul><li>GNU Free Documentation License </li></ul></ul><ul><ul><li>Creative Commons Attribution ShareAlike </li></ul></ul>