prev Translate Page next

An Ordinary Perl
6 Guide

by Dan Kogai

An Ordinary Perl
6 Guide

by Dan Kogai

An Ordinary Perl
5.10 Guide

by Dan Kogai

"Perl 6 Makes You Extraordinary"

Dan Kogai, in ふつうのPerl6入門 - YAPC::Asia 2007 Tokyo Sessions
でも...
いつまでもリリースされない... - 絶望した - はてなセリフ
というわけではないのですが
Perl6はとりあえずポロロッカ星人
のみなさんにまかせて
今回はPerl 5.10を紹介

前回までのあらすじ

2002 5.8.0
2003 5.8.1 5.8.2
2004 5.8.3 5.8.4 5.8.5 5.8.6
2005 5.8.7
2006 5.8.8 ←今ここ

今回

2007 5.8.9 # これも出ます、一応
     5.10  # 新バージョン; 10月予定
     6.0   # ポロロッカ星より

5.10の新機能

feature プラグマ

use feature qw/say switch/; # ひとつづつ
use feature qw/:5.10/;      # いっぺんにまとめて
use 5.10                    # これでもおk

feature プラグマ

レキシカルスコープです。
{
   use feature 'say';
   say "YES:)";
}
print "NO:(";

say

err

$c = defined($a) ? $a : $b; # マンドクサイ

err

$c = $a // $b; # こう書けます

err

低優先度版もあり〼

use feature qw/dor err/;
fileno($fh) dor die "that's not a filehandle";
fileno($fh) err die "that's not a filehandle";

state変数

state変数

今までは...
{
  my $i = 0;
  sub incr { $i++ };
}

state変数

これからは...
use feature 'state';
sub incr {
  state $i = 0;
  $i++;
}

given ~ when

given ~ when

use feature 'switch';
given($cond){
  when (/pat/){ ... }
  when ($num) { # $_ == $num }
  default { ... }
}

foreach ~ when

use feature 'switch';
foreach (@array){
  when (/pat/){ ... }
  when ($num) { # $_ == $num }
  default { ... }
}

~~

use feature '~~';
@array ~~ $x    and say "$x exists";
/弾/ ~~ $str    and say "空気嫁";
/弾/ ~~ @array  and say "自重汁";

Regexp

%^H

その他
詳しくは....
perldoc perl595delta
10月を待てない人は....
rsync -avz \
  rsync://ftp.linux.activestate.com/perl-current/ \
  perl-curent

Thank you!

Questions?