What's new in Perl 5.10?

  • 33,079 views
Uploaded on

Perl 5.10 will be the next new stable version of Perl. Find out what features it will have.

Perl 5.10 will be the next new stable version of Perl. Find out what features it will have.

More in: Business , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
33,079
On Slideshare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
668
Comments
1
Likes
20

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. What is new in Perl 5.10?
    • Paul Fenwick
    • Audrey Tang
    • Leon Brocard
  • 2. slidehist
    • Monday: I'm presenting?
    • Tuesday: download Paul's slides
    • Wednesday: tweak design
    • Thursday: play with fonts
    • Friday: argh slides on a plane
    • Saturday: release!
  • 3. perlhist
    • 1987: 1.0
    • 1988: 2.0
    • 1989: 3.0...
    • 1991: 4.0...
    • 1994: 5.0
  • 4. perlhist 5.0
    • 1994: 5.0
    • 1995: 5.1
    • 1996: 5.2, 5.3
    • 1997: 5.4
    • 1998: 5.5...
    • 2000: 5.6...
    • 2002: 5.8
  • 5. 5.8 perlhist
    • 2002: 5.8.0
    • 2003: 5.8.1, 5.8.2
    • 2o04: 5.8.3, 5.8.4, 5.8.5, 5.8.6
    • 2005: 5.8.7
    • 2006: 5.8.8
  • 6. 2007
    • Stable: 5.8.9
    • New: 5.10
    • New new: 6.0.0
  • 7. New features
    • Perl 5.10 has new features
    • Sorry Sebastian
  • 8. New?
    • new lexically-scoped feature pragma:
    • use feature qw(say switch);
    • use feature qw(:5.10);
    • use 5.10;
  • 9. Optimise programmer time
    • Most advanced programming language ever!
    • Perl: print “hello ”
    • Perl 6: say “hello”
    • Perl 5.10: say “hello”
  • 10. Save typing
    • My poor fingers!
    • Also none of this nasty quoting business
    • This might seem like it's trivial...
  • 11. Or
    • $c = $a | | $b is handy
    • confused by empty string, undef or zero
  • 12. Defined or
    • $c = $a // $b is handier
    • same as $c = defined($a) ? $a : $b
  • 13. dor and err
    • There's also low-precedence //
    • use feature qw(dor err);
    • fileno($x) dor die 'That's not a filehandle';
    • fileno($x) err die 'That's not a filehandle';
  • 14. State variables
    • The old way of having a persistent variable:
    • { my $i = 0; sub incrementor { return $i++; } }
  • 15. State variables
    • use feature 'state'; sub incrementor { state $i = 0; return $i++; }
  • 16. Local caches
    • State variables can live deep inside subroutines...
    • for my $x (...) { for my $y (...) { state %seen; next if $seen{$x}{$y}++; } }
  • 17. Switch
    • Perl 5.10 introduces a native switch statement.
    • Similar to Perl 6's switch, and Switch.pm (source filter)
    • Built into the Perl interpreter
  • 18. Guessing Game
    • use feature qw(switch say); my @guessed; my $num = int(rand 100)+1; while (my $guess = <STDIN>) { chomp $guess; given($guess) { when (/D/) { say &quot;Give me an integer&quot; } when (@guessed) { say &quot;You've tried that&quot; } when ($num) { say &quot;Just right!&quot;; last } when ($_ < $num) { say &quot;Too low&quot;; continue } when ($_ > $num) { say &quot;Too high&quot;; continue } push(@guessed,$_); } }
  • 19. foreach / when
    • use feature 'switch'; foreach (@cool_things) { when (/pirate/) { $pirate++ } when (/ninja/) { $ninja++ } when (/robot/) { $robot++ } say &quot;$_ doesn't look cool...&quot;; }
    • when automatically calls next at the end of its block
  • 20. Smart-match
    • use feature '~~'; if ($x ~~ @array) { say &quot;$x exists&quot; } if ($x ~~ /ninja/) { say &quot;Ninja in string&quot;} if (@x ~~ /ninja/) { say &quot;Ninja in array&quot; } if ($key ~~ %hash) { say &quot;$key exists&quot; } if ($subref ~~ $arg) { say 'sub($arg) true' }
  • 21. Smart-match
    • use feature '~~'; if (@array ~~ $x) { say &quot;$x exists&quot; } if (/ninja/ ~~ $x) { say &quot;Ninja in string&quot;} if (/ninja/ ~~ @x) { say &quot;Ninja in array&quot; } if (%hash ~~ $key) { say &quot;$key exists&quot; } if ($arg ~~ $subref) { say 'sub($arg) true' }
    • ~~ can be overloaded
  • 22. UNIVERSAL::DOES
    • Traditionally isa would be used to determine the capabilities of a class:
    • provides a way to show compatibility, without inheritance
    • $obj‐>isa('Logger');
    • $obj‐>DOES('Logger');
  • 23. Helicopter
    • package Helicopter; sub DOES { my ($this, $interface) = @_; return 1 if ($interface eq &quot;Airplane&quot;); return $this->SUPER::does($interface); }
  • 24. Constant (un-)folding
    • Perl 'folds' constants at compile time
    • 9+5 gets converted to 14
    • In Perl 5.10, exceptional constants are unfolded
    • They'll still throw run-time exceptions if you try to execute them
  • 25. Hash::Util::FieldHash
    • 5.10 comes with support for Field Hashes, which:
      • Can use references as hash keys
      • Reference-keys migrate correctly across threads
      • Entries to stale references are automatically deleted
    • (Inside-Out objects work nicely)
  • 26. Assertions
    • Perl 5.10 implements real assertions
    • Normally compiled away
    • Can be enabled on a per-module basis
    • # This is normally compiled away sub assert_sanity :assertion {...} # Enable assertions for MyModule perl -A=MyModule prog.pl
  • 27. User-defined lexical pragmata
    • We've used lexical pragmata for years: { use strict; ... }
    • In Perl 5.10 you can write your own!
    • %^H allows &quot;hints&quot; to be attached to the optree
    • use feature is implemented this way
  • 28. More modules
    • encoding::warnings
    • Math::BigInt::FastCalc
    • Time::Piece
    • Win32API::File
    • CPANPLUS
  • 29. CPANPLUS
    • Hi Jos!
    • It's about time, isn't it?
    • Means we have many other modules in the core...
  • 30. Regex engine
    • perlreguts
    • No longer recursive
    • Single char char-classes treated as literals
    • Trie optimisation of literal string alternations /foam|foal|foad/ => /foa[mld]/
    • Aho-Corasick start-point optimisation
    • Regex engine
    • Pluggable: use re::engine::PCRE;
    • Named capture buffers
    • /$(?<price>d+)/ ... $+{price}
    • More
  • 31. Other goodies
    • Misc Attribute Decoration
    • $AUTOLOAD can be tainted
    • Source filters in @INC
    • encodings::warnings is lexical
    • Better threads
    • Faster UTF-8
  • 32. More other goodies
    • Faster stat() on Windows
    • Relocatable installs
    • Overloading for re-blessed objects
    • Better Windows support
    • Smaller memory footprint (slightly faster)
    • More documentation
  • 33. More details?
    • http://search.cpan.org/dist/perl/pod/perl594delta.pod
  • 34. Questions?
  • 35. When will it be out?
    • Stable: 5.8.9 “by April 1st”
    • New: 5.10 “after lunch, before Christmas”
    • New new: 6.0.0 “after lunch, before Christmas”
  • 36. Any other questions?
  • 37. License
    • These slides are Copyright 2006 Paul Fenwick, Audrey Tang, Leon Brocard
    • The text may be distributed under your choice of any of the following:
      • The license terms of Perl itself
      • GNU Free Documentation License
      • Creative Commons Attribution ShareAlike