SlideShare a Scribd company logo
2017 年夏の Perl
Kenichi Ishigaki
@charsbar
YAPC::Fukuoka 2017
July 1, 2017
2017 年夏の Perl 5
Perl 5.26.0 が
出ました
既報の通り
今回はいろいろと壊れる
可能性があります
(※程度は人によります)
encoding プラグマ
の挙動が変わります
× use encoding 'cp932';
○ use encoding 'cp932', Filter => 1;
正規表現中の { の
扱いが変更に
5.16 で廃止、 5.22 以降警告が出ていたの
が
5.26 では死ぬように
$foo =~ /d{1,10}/; # ok
$foo =~ /d{1}/; # ok
$foo =~ /something{}/; # 5.26 ではエラー
$foo =~ /something[{]/; # ok
$foo =~ /something{/; # ok
$foo =~ /{}/; # これも ok
正規表現中の { の
扱いが変更に
$foo =~ /$hash{bar}/; # ok
$foo =~ /$notahash{}/; # 5.26 ではエラー
$foo =~ /${$foo}/; # ok ( デリファレン
ス )
$foo =~ /${${foo}}/; # ok ( デリファレン
ス )
$foo =~ /$foo/; # ok
$foo =~ /${foo}/; # 5.26 ではエラー
$foo =~ /${[^}]*}/; # ではこれは ???
5.28 で一度警告に戻して仕切り直すことになってい
POSIX::tmpnam() が
消えました
必要に応じて File::Temp の適切な関
数、メソッドを使ってください。
@INC から「 . 」が消え
ました
• inc::Module::Install
• テスト中の t::
• 環境設定用の do "localfile.pl"
• CGI スクリプトの require
"localfile.pl"
などを使っている方は要注意
@INC から「 . 」が消え
ました
• まずは CPAN クライアント
と Test::Harness をアップ
デート
• Minilla のようなオーサリン
グツールも
@INC から「 . 」が消え
ました
開発環境や CI 環境など、安全性が担
…保できる場合
•完全に移行が済むまでは環境変数
PERL_USE_UNSAFE_INC=1 が楽
( 移行が済んだら =0 に )
•特に大量のテストを抱えている場合
( 素の prove は . を戻してくれませ
@INC から「 . 」が消え
ました
• do や require は "./localfile.pl" の
ような書き方で回避できます
• do はファイルがなくても死なない
のでカレントディレクトリに該当
のファイルがあると新たに警告を
出すようになりました
do "localfile.pl" failed, '.' is no longer in @INC;
did you mean do "./localfile.pl"?
@INC から「 . 」が消え
ました
• use lib "." や perl -I. はカレント
ディレクトリを最優先させるので
、場合によってはかえって危険
• 迷ったら FindBin を使うか絶対パ
スで
• モジュールの中では @INC をいじ
らない。アプリやスクリプトの起
動時のみで十分
古い Perl 向けの対
策
• 配布するアプリやスクリプトの先
頭でカレントディレクトリを落と
すBEGIN { pop @INC, "." if $INC[-1] eq "" }
• sitecustomize.pl が有効なら、そ
の Perl を使う環境の @INC を調整
可能
レキシカルサブルーチン
が正式化
• 5.18 で実験的に導入
• 基本的にはコードリファレンスで代用可
能
{
my $foo = sub { ... };
$foo->();
}
{
my sub foo { ... }
foo();
}
レキシカルサブルーチン
が正式化
関数にモンキーパッチを当てるときには便
利 (?)
use Test::More;
subtest {
no warnings "redefine";
local *ok = sub { ... };
ok ...
};
use Test::More;
subtest {
my sub ok { ... }
ok ...
};
レキシカルサブルーチン
が正式化
万能ではないです
× my sub Test::More::ok { ... }
○ local *Test::More::ok = sub { ... };
use Test::More;
{
ok ...; # 先に出てきたものは当然ながら元のま
ま
my sub ok { ... }
}
ヒアドキュメント
が
インデント可能に{
my ($key, $value) = qw/foo bar/;
my $json_template = << "END";
{"$key": "$value"}
END
}
ヒアドキュメント
が
インデント可能に{
my ($key, $value) = qw/foo bar/;
my $json_template = <<~ "END";
{"$key": "$value"}
END
}
Unicode 9.0 サポー
トplackup -MEncode -e 'use 5.026; sub {[
200,
["Content-Type" => "text/plain"],
[encode_utf8(
"N{FIRST PLACE MEDAL} ".
"N{TUMBLER GLASS} ".
"N{SNEEZING FACE}"
)],
]}'
http://emojione.com
サブルーチンシグネチャ
がまともな速さに
use 5.020;
use experimental "signatures";
use Benchmark qw/cmpthese/;
cmpthese(10000000, {
no_signature => sub { no_sig(1, "value") },
signature => sub { sig(1, "value") },
});
sub no_sig { my ($num, $str) = @_; return "$num $str" }
sub sig ($num, $str) { return "$num $str";}
v5.20.0
Rate signature no_signature
signature 1261034/s -- -35%
no_signature 1926782/s 53% --
v5.26.0
Rate signature no_signature
signature 2020202/s -- -6%
no_signature 2155172/s 7% --
サブルーチンシグネチャ
がまともな速さに
@{^CAPTURE} 特殊変数
my $str = "2017-07-01: YAPC Fukuoka";
$str =~ /A([^:]+): (w+) (w+)/;
say "$1, $2, $3"; # 2017-07-01, YAPC, Fukuoka
my $str = "????-??-??: YAPC ???";
$str =~ /A([^:]+): (w+) (w+)?/;
say "$1, $2, $3"; # ????-??-??, YAPC, ( 警告 )
my $str = "????-??-??: YAPC ???";
my @capture = $str =~ /A([^:]+): (w+) (w+)?/;
say join ", ", @capture; # ????-??-??, YAPC, ( 警
告 )
my $str = "????-??-??: YAPC ???";
$str =~ /A([^:]+): (w+) (w+)?/;
say join ", ", @{^CAPTURE}; # ????-??-??, YAPC
%{^CAPTURE} 特殊変数
my $str = "2017-07-01: YAPC Fukuoka";
$str =~ /A
(?<date>[^:]+):s
(?<name>w*)s
(?<city>w*)
/x;
say "$+{date}, $+{name}, $+{city}";
# 2017-07-01, YAPC, Fukuoka
%{^CAPTURE} 特殊変数
my $str = "2017-07-01: YAPC Fukuoka";
$str =~ /A
(?<date>[^:]+):s
(?<name>w*)s
(?<city>w*)
/;
say "${^CAPTURE}{date}, ${^CAPTURE}{name},
${^CAPTURE}{city}";
実は特別扱いされていないために 5.26.0 では文字列埋め込
みがおかしな出力に ("{date}, {name}, {city}")
すでにパッチが提供されているので次版で直る見込み
詳しくは
perl(5260)?delta
を
5.28 で廃止が
予定されているも
の
異なる種類のハンドルの
共有はエラーに
5.28 からはファイルハンドルとディレクトリハンドルを
ひとつの変数で共有できなくなります
# 5.26 まで
open my $hd, '<', 'foo.txt';
opendir $hd, 'bar/';
say <$hd>; # foo.txt の中身
say readdir $hd; # bar ディレクトリ配下のファイル名
# 5.27.1
Cannot open $hd as a dirhandle: it is already open
as a filehandle
ヒアドキュメントの
終端は省略不可に
ヒアドキュメントの終端は明示してください
# 5.27.1
print <<; # NG
This has long been deprecated since 5.000.
# 5.26 までは上の空行が終端扱い
Use of bare << to mean <<"" is forbidden
関数呼び出しで継承元の
AUTOLOAD を呼ぶのは禁止
package A;
@ISA = qw/B/;
package B;
our @AUTOLOAD;
sub AUTOLOAD { ... }
package main;
A::foo();
# Use of inherited AUTOLOAD for non-
method A::foo() is no longer allowed
詳しくは
perldeprecation.pod
を
2017 年夏の Perl 6
あの「クリスマス」
から一年半が経ちま
した
「ロースト」のお味、試
してみましたか?
• Perl 6 では実装と仕様が明確に分
かれています
• ラリーが「クリスマス」に持って
きてくれたのは「公式テスト
(Repository Of All Spec Tests) 」の
クリスマス・バージョンです
$ perl6 -v
This is Rakudo version 2017.06 built on
MoarVM version 2017.06
implementing Perl 6.c.
• say $*PERL.version; # v6.c
• say $*PERL.name; # Perl 6
• say $*PERL.compiler.version; # v2017.06
• say $*PERL.compiler.name; # rakudo
• say $*VM.version; # v2017.06
• say $*VM.name; # moar
use 文で制御できるのは v6.c の部分だけ
2017.05 からは
perl6 -V がさらに充
実特に CPAN Testers との統合を目指して、 OS
distribution や Kernel 情報なども表示されるようになっ
ています$ perl6 -V
distro::auth=http://www.debian.org/
distro::desc=2017-06-29T03:22:49.796661+09:00
distro::is-win=False
distro::name=debian
...
kernel::archname=x86_64-linux
kernel::name=linux
kernel::version=3.16.0.4.amd.64
...
開発はいまも活発
に続いています
パフォーマンスや
安定性も着実に向上
Jonathan Worthington 氏が
2 期目の作業を完了しまし
た
(3 期目の助成金も申請中 )- http://news.perlfoundation.org/2017/04/perl-6-performance-and-reliabi-3.html
- https://6guts.wordpress.com/2017/06/08/sorting-out-synchronous-io/
Perl 6 の「安定
性」 ?
• テストがないものは実装があっても
「仕様」ではありません
• 疑問に思ったら設計文書ではなく公式
仕様テスト (ROAST) をご確認ください
• 互換性が壊れるような仕様変更につい
ては ( 開発版には先行実装が含まれる
かもしれませんが ) 正式には次のバー
ジョンに持ち越されます
中には特定の環境にしか公式テス
トが存在しないものがあります
given $*DISTRO.name {
when "macosx" {
#?rakudo.jvm 3 skip "file system events NYI? RT #124828"
subtest &macosx, "does watch-path work on Mac OS X";
unlink $filename; # in case we missed the cleanup
ok !$filename.IO.e, "make sure we don't have a file (2)";
subtest { macosx :io-path }, "does IO::Path.watch work on
Mac OS X";
}
default {
skip "Only OSX tests available", 3;
}
}
perl6/roast/S17-supply/watch-path.t
(for IO::Notification.watch-path)
IOwesomeness
Zoffix Znet 氏が I/O まわりの作業を完了しまし
た
• 実装しかなかった I/O 関係のコードすべ
てにテストとドキュメントが用意されま
した
• 仕様に含めない決定が下されたコードは
( 6.d で)削除されることになります
• パフォーマンスも改善されました
http://blogs.perl.org/users/zoffix_znet/2017/05/completion-
report-perl-6-io-tpf-grant.html
Unicode サポート
• Perl 6 が特にこだわっている分野
のひとつ
• Samantha McVey 氏が collation や
grapheme の扱いを強化中
Unicode サポート
say 「こんにちはこんにちは」 ; # 半角「 」のみ
my $ 税率 = 1.08; ($ 金額 ×$ 税率 ).say;
say 100² ÷ ⅕; # 50000;
# say 100 ** 2 / unival("x[2155]");
say "in-between" if 10 ≦ $num ≦ 1000;
say 「こんにちはこんにちは」 ; # 半角「 」のみ
my $ 税率 = 1.08; ($ 金額 ×$ 税率 ).say;
say 100² ÷ ⅕; # 50000;
# say 100 ** 2 / unival("x[2155]");
say "in-between" if 10 ≦ $num ≦ 1000;
Unicode サポート
見かけ上 1 文字に見えてしまう肌色修飾子なども正しく扱えます
$ perl5 -E 'say length "N{MAN}N{EMOJI MODIFIER FITZPATRICK TYPE-5}"' # 2
$ perl6 -e 'say "c[MAN]c[EMOJI MODIFIER FITZPATRICK TYPE-5]".chars' # 1
$ perl6 -e 'say "c[MAN]c[EMOJI MODIFIER FITZPATRICK TYPE-5]".codes' # 2
親切なエラーメッセー
ジPerl 5 ユーザがやらかしがちなミスは実行
時に正しい書き方を教えてくれます
$ perl5 -E 'say length "N{MAN}N{EMOJI MODIFIER FITZPATRICK TYPE-5}"'
$ perl6 -e 'say length "N{MAN}N{EMOJI MODIFIER FITZPATRICK TYPE-5}"'
# Unsupported use of N{CHARNAME}; in Perl 6 please use c[CHARNAME]
$ perl6 -e 'say length "c[MAN]c[EMOJI MODIFIER FITZPATRICK TYPE-5]"'
# Undeclared routine:
# length used at line 1. Did you mean 'elems', 'chars', 'graphs', 'codes'?
親切なエラーメッセー
ジ
2017.05 からは Perl 5 とは無関係な
ミスも教えてくれるようになりまし
た
$ perl6 -e 'say 42.195.Inf'
No such method 'Inf' for invocant of type 'Rat'.
Did you mean 'Int'?
perl6-js
ついに誰でもコンパイルが可能になりま
した (Node.js 7.x が必要 )
$ git clone https://github.com/rakudo/rakudo.git rakudo-js
$ cd rakudo-js
$ git checkout js
$ perl Configure.pl --backends=moar,js --gen-nqp --gen-moar
$ make js-all
$ ./perl6-js -v
This is Rakudo version 2017.06-223-g85a481c built on JS
implementing Perl 6.c.
$ ./perl6-js -e 'say(123)'
$ make js-spectest
http://blogs.perl.org/users/pawel_murias/2017/06/rakudojs-update---
build-sanely-and-passes-some-spec-tests.html
エコシステム
https://modules.perl6.org/
•2017 年 6 月の時点で 840 くら
い
•最終更新が「クリスマス」以
前のものは動かないかも
Perl 6 Ecosystem
Toaster最新のコミットでどの程度エコシステムが
壊れたかを確認できるように
https://toast.perl6.party/
https://perl6.party/post/Perl-6-Release-Quality-Assurance-Full-
Ecosystem-Toaster
Perl 6 のモジュールを書
く
とりあえず何か書いてみたいという
方は
skaji さんの App::Mi6 を
# panda は正式に開発終了になりました
$ zef install App::Mi6
===> Searching for: App::Mi6
===> Updated cpan mirror: https://raw.githubusercontent.com/ugexe/Perl6-
ecosystems/master/cpan.json
===> Updated p6c mirror: http://ecosystem-api.p6c.org/projects.json
$ mi6 new Your::Perl6::Module
書き上がったモジュールは
CPAN へ
5 月に開催された Perl Toolchain Summit
で Perl 6 のディストリビューションもそ
のまま PAUSE にアップロードできるよう
になりました
• 内部的には作者の Perl6 ディレクトリに移動
• App::Mi6 を最新にすれば CPAN へのアップ
ロードも可能に
$ mi6 dist
$ mi6 upload
書き上がったモジュールは
CPAN へ
最新の zef は CPAN のモジュールも認識し
ます
$ zef list --max=100
...
===> Found via Zef::Repository::Ecosystems<cpan>
Inline:ver('1.2.1')
Inline:ver('1.2')
Inline:ver('1')
IO::Glob:ver('0.1'):auth('github:zostay')
Text::CSV:ver('0.007'):auth('github:Tux')
Text::CSV:ver('0.008'):auth('github:Tux')
Data::Selector:ver('1.01')
Data::Selector:ver('1.02')
NativeCall:ver('1')
...
6.d.PREVIEW
• Rakudo 2017.02 からは最初の 6.c 非互
換機能となる nonblocking await の実装
が入っています
• 試す場合は use v6.d.PREVIEW; で
https://github.com/perl6/roast/blob/master/S17-supply/syntax-nonblocking-await.t
これから学ぶなら
当面はググるよりも信頼できる情報源を頼るの
が吉
•Perl 6 の各種アドベントカレンダー
– https://perl6advent.wordpress.com/
roast/integration/ 以下のテストも参照
– http://qiita.com/advent-calendar/2016/perl6
– http://qiita.com/advent-calendar/2015/perl6
•Perl 6 入門 : http://ja.perl6intro.com
•RosettaCode
https://rosettacode.org/wiki/Category:Perl_6
•公式テスト
•perl6.org
6.c 対応の書籍も続々
と書かれています
https://perl6book.com/
6.c 対応の書籍も続々
と書かれています
• Perl 6 at a Glance (Andrew Shitov; 2017.01.01)
https://deeptext.media/perl6-at-a-glance/ ( 電子書籍版も出ました )
• Think Perl 6
(Laurent Rosenfeld, Allen B. Downey; 2017.05.25)
http://shop.oreilly.com/product/0636920065883.do
• Migrating to Perl 6 (Andrew Shitov)
https://deeptext.media/migrating-to-perl6
• Learning Perl 6 (brian d foy)
https://www.learningperl6.com
6.c 対応の書籍も続々
と書かれています
• Perl 6 Fundamentals (Moritz Lenz)
http://www.apress.com/us/book/9781484228982
• Searching and Parsing with Perl 6 Regexes (Moritz Lenz)
https://leanpub.com/perl6regex
• Web Application Development in Perl 6 (Gabor Szabo)
• Using Perl 6 (Andrew Shitov)
• Perl 6 Deep Dive (Andrew Shitov)
その他の情報源
• Weekly changes in and around Perl 6
https://p6weekly.wordpress.com
• https://twitter.com/perl6org
• Youtube の Perl 6 関連ビデオ
http://bit.ly/perl6_english_video
• 次期バージョンについて
– https://github.com/perl6/specs/blob/master/v6d.pod
– https://github.com/rakudo/rakudo/blob/nom/docs/language_versions.md
• WEB+DB PRESS Vol.93 「 Perl 6 の歩き方」
http://gihyo.jp/dev/serial/01/perl-hackers-hub/003901
2017 年後半の主要
Perl 関連イベント
The Perl Conferences (YAPC)
•2017.06.18-23 (Alexandria, Virginia, USA) ( 終了 )
•2017.08.09-11 (Amsterdam, Netherlands)
Swiss Perl Workshop 2017
•2017.08.25-26 (Villars-sur-Ollon, Switzerland)
London Perl Workshop 2017
•2017.11.25 (London, UK)
Thank you

More Related Content

PPT
CPANの依存モジュールをもう少し正しく検出したい
PPT
2017年春のPerl
PPTX
CMSとPerlで遊ぼう
PPT
How to debug a perl script using gdb
PPTX
php7's ast
PPTX
PHP AST 徹底解説(補遺)
PPTX
PHP AST 徹底解説
PDF
最近の PHP の話
CPANの依存モジュールをもう少し正しく検出したい
2017年春のPerl
CMSとPerlで遊ぼう
How to debug a perl script using gdb
php7's ast
PHP AST 徹底解説(補遺)
PHP AST 徹底解説
最近の PHP の話

What's hot (20)

PDF
about Perl5.10
PDF
OPcache の最適化器の今
KEY
モダンmod_perl入門 #yapcasia
PPTX
PHP と SAPI と ZendEngine3 と
PPTX
php-src の歩き方
PDF
PHPの今とこれから2014
PDF
Ruby 2.5
PDF
Everyday Life with clojure.spec
PDF
PHPの今とこれから2021
PDF
PDF
Good Parts of PHP and the UNIX Philosophy
PDF
『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題
PDF
Norikraで作るPHPの例外検知システム YAPC::Asia Tokyo 2015 LT
PPT
PHP, Now and Then 2011
PDF
PHPの今とこれから 2013
PDF
VarnishではじめるESI
PDF
15分でCakePHPを始める方法(Nseg 2013-11-09 )
PDF
omoon.org の裏側 〜FuelPHP の task 活用例〜
PDF
awk v.s. bashどっちが強い?@OSC2011Tokyo
about Perl5.10
OPcache の最適化器の今
モダンmod_perl入門 #yapcasia
PHP と SAPI と ZendEngine3 と
php-src の歩き方
PHPの今とこれから2014
Ruby 2.5
Everyday Life with clojure.spec
PHPの今とこれから2021
Good Parts of PHP and the UNIX Philosophy
『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題
Norikraで作るPHPの例外検知システム YAPC::Asia Tokyo 2015 LT
PHP, Now and Then 2011
PHPの今とこれから 2013
VarnishではじめるESI
15分でCakePHPを始める方法(Nseg 2013-11-09 )
omoon.org の裏側 〜FuelPHP の task 活用例〜
awk v.s. bashどっちが強い?@OSC2011Tokyo
Ad

Similar to 2017年夏のPerl (20)

PPT
2018年夏のPerl5
KEY
20年越しで Perl 4 to 5 した話
KEY
Perlで伝統芸能
PDF
Perl勉強会#2資料
ZIP
実践Sass 後編
KEY
Mojoliciousをウェブ制作現場で使ってみてる
PDF
GNU awk (gawk) を用いた Apache ログ解析方法
PDF
姫路IT系勉強会 Vol.11 第0回L-1グランプリ bash
PPTX
詳説ぺちぺち
PDF
Local php-100828 2
PDF
Sass(SCSS)について
PPTX
知ってるようで意外と知らないPHPの便利関数
PPTX
URLで遊ぼう
PDF
Okinawapm #1
PDF
とあるプロジェクトのつらみなコード
PDF
Rubyにおける構文追加の試み 〜ボクとRubyと俺々文法〜
PDF
zsh とわたし
PDF
Niigata.pm #1
PDF
Perl6で遊ぼう
PDF
2018年夏のPerl5
20年越しで Perl 4 to 5 した話
Perlで伝統芸能
Perl勉強会#2資料
実践Sass 後編
Mojoliciousをウェブ制作現場で使ってみてる
GNU awk (gawk) を用いた Apache ログ解析方法
姫路IT系勉強会 Vol.11 第0回L-1グランプリ bash
詳説ぺちぺち
Local php-100828 2
Sass(SCSS)について
知ってるようで意外と知らないPHPの便利関数
URLで遊ぼう
Okinawapm #1
とあるプロジェクトのつらみなコード
Rubyにおける構文追加の試み 〜ボクとRubyと俺々文法〜
zsh とわたし
Niigata.pm #1
Perl6で遊ぼう
Ad

More from charsbar (20)

PPT
Common boolean class_for_perl5
PDF
萬國之津梁
PDF
Better detection of what modules are used by some Perl 5 code
PPT
Json(::PP) is a-changing
PPT
2016年のPerl (Long version)
PPT
JSON, JSON::PP, and more
PPT
perl language update
PDF
2013年のCPANモジュール作成事情
PDF
What you need to remember when you upload to CPAN
PPT
On UnQLite
PPT
typemap in Perl/XS
PDF
Analyze CPAN, Analyze Community
PDF
Annual Report 2012
PDF
DBD::SQLite
PDF
CPANTS: Kwalitative website and its tools
PPT
CPANTS 2012
PPT
Revisiting ppm
PDF
Mojolicious::Liteを使ってみよう
PPT
変数、リファレンス
PPT
關於perl的 文件翻譯
Common boolean class_for_perl5
萬國之津梁
Better detection of what modules are used by some Perl 5 code
Json(::PP) is a-changing
2016年のPerl (Long version)
JSON, JSON::PP, and more
perl language update
2013年のCPANモジュール作成事情
What you need to remember when you upload to CPAN
On UnQLite
typemap in Perl/XS
Analyze CPAN, Analyze Community
Annual Report 2012
DBD::SQLite
CPANTS: Kwalitative website and its tools
CPANTS 2012
Revisiting ppm
Mojolicious::Liteを使ってみよう
変数、リファレンス
關於perl的 文件翻譯

2017年夏のPerl