Your SlideShare is downloading. ×
0
Perl 5.10
OSDC.tw 2009 4/19


scw at csie dot org
Who
Who?


     Larry Wall
Rafa¨l Garcia-Suarez
    e
When
When?


Perl 5.8.0:   July 18, 2002
When?


Perl 5.8.0:   July 18, 2002
Perl 5.8.9:   Dec 14, 2008
When?


Perl 5.10.0:   Dec 18, 2007
When?


Perl 5.10.0:   Dec 18, 2007
Perl 6:        By Xmas
What
What?


Compatible (almost)
  major upgrade
What?


 New language features
Interpreter improvements
What?


Features and inspiration
     from Perl 6
Where
Where?

Debian 5.0 lenny
Ubuntu 8.10 intrepid
Fedora 9
Where?


FreeBSD ports (2009-03-28)
ActivePerl 5.10.0.1004
How
How?


apt-get install perl
yum update perl
How?

portsnap fetch update
cd lang/perl5.10
make install clean
How?

portsnap fetch update
cd lang/perl5.10
make install clean
read /usr/ports/UPDATING !!!
Not root?
Not root!

$ wget http://www.cpan.org/authors/id/
  R/RG/RGARCIA/perl-5.10.0.tar.gz
$ tar zxf perl-5.10.0.tar.gz; cd perl-...
Why
a//a
a||a
Why?

$a // ”Comment?”
Why?

$a // ”Comment?”
defined $a ?
  $a : ”Comment?”
defined-or


Apply defined-or patch against
     perl 5.8 works, too
defined-or

my $price = mysql select(...)
           // ”not found”;
say ”Price at $price”
say


say = print + -l
Not enabled by default
feature


use feature qw( )
say, switch, state
feature

use feature ”:5.10”
use 5.010
use v5.10
perl -E
feature


      switch
In correct English!!
switch
given($foo) {
  when (undef) { say ’$foo is undefined’ }
  when (”foo”) { say ’$foo is str ”foo”’ }
  when ([1,3,5,7...
when

my $count = 0;
for (@array) {
  when (”foo”) { ++$count }
}
say ”array contains $count copies of ’foo’”;
given, when & default


given(EXPR) = do{ $ = EXPR; ... }
when($foo) = when($ ˜˜$foo)
default = when(1 == 1)
smart match

”Smart matching in detail” in perlsyn
$a˜˜$b the same to $b˜˜$a
keys for hash
content for array
PerlRE
Engine



De-recursivised
Engine




Trie
Engine



Aho-Corasick
Named Capture
Named capture

/(?<ip> d+.d+.d+.d+)
.-.-.[(?<time>.*?)]
.”(?<method>GET|POST)
.(?<request>[ˆ ]+)
/x
Named capture

/(?<ip> d+.d+.d+.d+)
.-.-.[(?<time>.*?)]
.”(?<method>GET|POST)
.(?<request>[ˆ ]+)
/x
$+{’ip’, ’time’, ’meth...
backreference

/(.)1/
/(.)g1/
/(.)g{1}/
/(.)g{-1}/
/(?<letter>.)g{letter}/
/(?<letter>.)k<letter>/
Regexp::Keep
Regexp::Keep


s/(.*)?.*/$1/g
Regexp::Keep


s/(.*)?.*/$1/g
s/.*K?.*//g
PerlRE not Regular
Recursive
/ˆ(                        # start of line, capture buffer 1
      <                    # match an opening angle ...
Recursive
/ˆ(                       # start of line, capture buffer 1
      <                   # match an opening angle br...
Recursive
/ˆ(                        # start of line, capture buffer 1
      <                    # match an opening angle ...
Backtracking Control Verbs
(*FAIL)
(*ACCEPT)
On (*FAIL)...
On (*FAIL)...


   (*PRUNE)
estart this trial (:)
On (*FAIL)...


aaaaaaaaaaaaaa
/a*(*PRUNE)a/
On (*FAIL)...


  (*THEN)
 ext branch (::)
On (*FAIL)...


aaaaaaaaaaaaa
/a*(*THEN)a/
On (*FAIL)...


aaaaaaaaaaaaaaaa
/a*(*THEN)a|a+/
On (*FAIL)...


  (*COMMIT)
ail the match (:::)
On (*FAIL)...


aaaaaaaaaaaaaaaa
/a*(*COMMIT)a/
demo
parse string
man perlre
man perldelta
Thank you!
Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009
Upcoming SlideShare
Loading in...5
×

Perl 5.10 on OSDC.tw 2009

1,289

Published on

Presentation of Perl 5.10 on OSDC.tw 2009, 4/19 by scw

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,289
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
42
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Perl 5.10 on OSDC.tw 2009"

  1. 1. Perl 5.10
  2. 2. OSDC.tw 2009 4/19 scw at csie dot org
  3. 3. Who
  4. 4. Who? Larry Wall Rafa¨l Garcia-Suarez e
  5. 5. When
  6. 6. When? Perl 5.8.0: July 18, 2002
  7. 7. When? Perl 5.8.0: July 18, 2002 Perl 5.8.9: Dec 14, 2008
  8. 8. When? Perl 5.10.0: Dec 18, 2007
  9. 9. When? Perl 5.10.0: Dec 18, 2007 Perl 6: By Xmas
  10. 10. What
  11. 11. What? Compatible (almost) major upgrade
  12. 12. What? New language features Interpreter improvements
  13. 13. What? Features and inspiration from Perl 6
  14. 14. Where
  15. 15. Where? Debian 5.0 lenny Ubuntu 8.10 intrepid Fedora 9
  16. 16. Where? FreeBSD ports (2009-03-28) ActivePerl 5.10.0.1004
  17. 17. How
  18. 18. How? apt-get install perl yum update perl
  19. 19. How? portsnap fetch update cd lang/perl5.10 make install clean
  20. 20. How? portsnap fetch update cd lang/perl5.10 make install clean read /usr/ports/UPDATING !!!
  21. 21. Not root?
  22. 22. Not root! $ wget http://www.cpan.org/authors/id/ R/RG/RGARCIA/perl-5.10.0.tar.gz $ tar zxf perl-5.10.0.tar.gz; cd perl-5.10.0 $ ./Configure -Dprefix=/usr/local ˜ -Duserelocatableinc $ make -j 8 all test install
  23. 23. Why
  24. 24. a//a
  25. 25. a||a
  26. 26. Why? $a // ”Comment?”
  27. 27. Why? $a // ”Comment?” defined $a ? $a : ”Comment?”
  28. 28. defined-or Apply defined-or patch against perl 5.8 works, too
  29. 29. defined-or my $price = mysql select(...) // ”not found”; say ”Price at $price”
  30. 30. say say = print + -l Not enabled by default
  31. 31. feature use feature qw( ) say, switch, state
  32. 32. feature use feature ”:5.10” use 5.010 use v5.10 perl -E
  33. 33. feature switch In correct English!!
  34. 34. switch given($foo) { when (undef) { say ’$foo is undefined’ } when (”foo”) { say ’$foo is str ”foo”’ } when ([1,3,5,7,9]) { say ’$foo is an odd digit’; continue; } when ($ < 100) { say ’$foo under 100’ } when (&func) { say ’func($foo) true’ } default { die q(I don’t know what to do
  35. 35. when my $count = 0; for (@array) { when (”foo”) { ++$count } } say ”array contains $count copies of ’foo’”;
  36. 36. given, when & default given(EXPR) = do{ $ = EXPR; ... } when($foo) = when($ ˜˜$foo) default = when(1 == 1)
  37. 37. smart match ”Smart matching in detail” in perlsyn $a˜˜$b the same to $b˜˜$a keys for hash content for array
  38. 38. PerlRE
  39. 39. Engine De-recursivised
  40. 40. Engine Trie
  41. 41. Engine Aho-Corasick
  42. 42. Named Capture
  43. 43. Named capture /(?<ip> d+.d+.d+.d+) .-.-.[(?<time>.*?)] .”(?<method>GET|POST) .(?<request>[ˆ ]+) /x
  44. 44. Named capture /(?<ip> d+.d+.d+.d+) .-.-.[(?<time>.*?)] .”(?<method>GET|POST) .(?<request>[ˆ ]+) /x $+{’ip’, ’time’, ’method’, ’request’}
  45. 45. backreference /(.)1/ /(.)g1/ /(.)g{1}/ /(.)g{-1}/ /(?<letter>.)g{letter}/ /(?<letter>.)k<letter>/
  46. 46. Regexp::Keep
  47. 47. Regexp::Keep s/(.*)?.*/$1/g
  48. 48. Regexp::Keep s/(.*)?.*/$1/g s/.*K?.*//g
  49. 49. PerlRE not Regular
  50. 50. Recursive /ˆ( # start of line, capture buffer 1 < # match an opening angle brack (? : # match one of: [ˆ <>]+ # one or more non angle br | # ... or ... (?1) # recurse to bracket 1 and try )∗ # 0 or more times. > # match a closing angle bracket ) # end capture buffer one $/x # end of line
  51. 51. Recursive /ˆ( # start of line, capture buffer 1 < # match an opening angle brack (? : # match one of: (? > [ˆ <>]+ # one or more non angle br ) | # ... or ... (?1) # recurse to bracket 1 and try )∗ # 0 or more times. > # match a closing angle bracket ) # end capture buffer one $/x # end of line
  52. 52. Recursive /ˆ( # start of line, capture buffer 1 < # match an opening angle brack (? : # match one of: [ˆ <>] + + # one or more non angle b | # ... or ... (?1) # recurse to bracket 1 and tr )∗ # 0 or more times. > # match a closing angle bracket ) # end capture buffer one $/x # end of line
  53. 53. Backtracking Control Verbs
  54. 54. (*FAIL)
  55. 55. (*ACCEPT)
  56. 56. On (*FAIL)...
  57. 57. On (*FAIL)... (*PRUNE) estart this trial (:)
  58. 58. On (*FAIL)... aaaaaaaaaaaaaa /a*(*PRUNE)a/
  59. 59. On (*FAIL)... (*THEN) ext branch (::)
  60. 60. On (*FAIL)... aaaaaaaaaaaaa /a*(*THEN)a/
  61. 61. On (*FAIL)... aaaaaaaaaaaaaaaa /a*(*THEN)a|a+/
  62. 62. On (*FAIL)... (*COMMIT) ail the match (:::)
  63. 63. On (*FAIL)... aaaaaaaaaaaaaaaa /a*(*COMMIT)a/
  64. 64. demo parse string
  65. 65. man perlre
  66. 66. man perldelta
  67. 67. Thank you!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×