=encoding euc-jp =head1 NAME =begin original perlcheat - Perl 5 Cheat Sheet =end original perlcheat - Perl 5 チートシート =head1 DESCRIPTION =begin original This 'cheat sheet' is a handy reference, meant for beginning Perl programmers. Not everything is mentioned, but 195 features may already be overwhelming. =end original この「チートシート」は Perl プログラミングの初心者のためのリファレンスです。 全てについて言及しているわけではありませんが、195 要素というのは 半端ではありません。 =head2 The sheet (チートシート) =begin original CONTEXTS SIGILS ref ARRAYS HASHES void $scalar SCALAR @array %hash scalar @array ARRAY @array[0, 2] @hash{'a', 'b'} list %hash HASH $array[0] $hash{'a'} &sub CODE *glob GLOB SCALAR VALUES FORMAT number, string, ref, glob, undef REFERENCES \ reference $$foo[1] aka $foo->[1] $@%&* dereference $$foo{bar} aka $foo->{bar} [] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2] {} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2] \() list of refs NUMBERS vs STRINGS LINKS OPERATOR PRECEDENCE = = perldoc.perl.org -> + . search.cpan.org ++ -- == != eq ne cpan.org ** < > <= >= lt gt le ge pm.org ! ~ \ u+ u- <=> cmp p3rl.org =~ !~ perlmonks.org * / % x SYNTAX + - . foreach (LIST) { } for (a;b;c) { } << >> while (e) { } until (e) { } named uops if (e) { } elsif (e) { } else { } < > <= >= lt gt le ge unless (e) { } elsif (e) { } else { } == != <=> eq ne cmp ~~ given (e) { when (e) {} default {} } & | ^ REGEX METACHARS REGEX MODIFIERS && ^ string begin /i case insensitive || // $ str end (bfr \n) /m line based ^$ .. ... + one or more /s . includes \n ?: * zero or more /x ignore wh.space = += -= *= etc ? zero or one /p preserve , => {3,7} repeat in range /a ASCII /aa safe list ops | alternation /l locale /d dual not [] character class /u Unicode and \b word boundary /e evaluate /ee rpts or xor \z string end /g global () capture /o compile pat once DEBUG (?:p) no capture -MO=Deparse (?#t) comment REGEX CHARCLASSES -MO=Terse (?=p) ZW pos ahead . [^\n] -D## (?!p) ZW neg ahead \s whitespace -d:Trace (?<=p) ZW pos behind \K \w word chars (?p) no backtrack \pP named property perl -V:ivsize (?|p|p)branch reset \h horiz.wh.space (?&NM) cap to name \R linebreak \S \W \D \H negate FUNCTION RETURN LISTS stat localtime caller SPECIAL VARIABLES 0 dev 0 second 0 package $_ default variable 1 ino 1 minute 1 filename $0 program name 2 mode 2 hour 2 line $/ input separator 3 nlink 3 day 3 subroutine $\ output separator 4 uid 4 month-1 4 hasargs $| autoflush 5 gid 5 year-1900 5 wantarray $! sys/libcall error 6 rdev 6 weekday 6 evaltext $@ eval error 7 size 7 yearday 7 is_require $$ process ID 8 atime 8 is_dst 8 hints $. line number 9 mtime 9 bitmask @ARGV command line args 10 ctime 10 hinthash @INC include paths 11 blksz 3..10 only @_ subroutine args 12 blcks with EXPR %ENV environment =end original CONTEXTS 印 ref 配列 ハッシュ 無効 $変数 SCALAR @array %hash スカラ @配列 ARRAY @array[0, 2] @hash{'a', 'b'} リスト %ハッシュ HASH $array[0] $hash{'a'} &関数 CODE スカラ値 *グロブ GLOB 数値, 文字列, リファレンス, FORMAT グロブ, undef リファレンス \ リファレンス $$foo[1] は $foo->[1] $@%&* デリファレンス $$foo{bar} は $foo->{bar} [] 無名配列ref ${$$foo[1]}[2] は $foo->[1]->[2] {} 無名ハッシュref ${$$foo[1]}[2] は $foo->[1][2] \() リストのリファレンス 数値 vs 文字列 リンク 演算子の優先順位 = = perldoc.perl.org -> + . search.cpan.org ++ -- == != eq ne cpan.org ** < > <= >= lt gt le ge pm.org ! ~ \ u+ u- <=> cmp p3rl.org =~ !~ perlmonks.org * / % x 文法 + - . foreach (LIST) { } for (a;b;c) { } << >> while (e) { } until (e) { } 名前付き単項演算子 if (e) { } elsif (e) { } else { } < > <= >= lt gt le ge unless (e) { } elsif (e) { } else { } == != <=> eq ne cmp ~~ given (e) { when (e) {} default {} } & | ^ REGEX METACHARS REGEX MODIFIERS && ^ 文字列先頭 /i 大小文字無視 || // $ 文字列末尾(\nの前) /m ^$ベースの行 .. ... + 1以上 /s .に\nを含む ?: * 0以上 /x 空白を無視 = += -= *= etc ? 0か1 /p 保存 , => {3,7} 範囲の繰り返し /a ASCII /aa 安全 list ops | または /l ロケール /d 双方 not [] 文字クラス /u Unicode and \b 単語境界 /e evalする /ee 反復 or xor \z 文字列末尾 /g グローバル () 捕捉 /o コンパイル1回 DEBUG (?:p) 捕捉しない -MO=Deparse (?#t) コメント 正規表現文字クラス -MO=Terse (?=p) ZW 正前方 . [^\n] -D## (?!p) ZW 負前方 \s 空白 -d:Trace (?<=p) ZW 正後方 \K \w 単語文字 (?p) 非バックトラック \pP 名前付き特性 perl -V:ivsize (?|p|p)枝リセット \h 水平空白 (?&NM) 名前つき捕捉 \R 行分割 \S \W \D \H は逆 関数の返り値 stat localtime caller 特殊変数 0 dev 0 秒 0 package $_ デフォルト変数 1 ino 1 分 1 filename $0 プログラム名 2 mode 2 時 2 line $/ 入力セパレータ 3 nlink 3 日 3 subroutine $\ 出力セパレータ 4 uid 4 月-1 4 hasargs $| 自動flush 5 gid 5 年-1900 5 wantarray $! sys/libcallエラー 6 rdev 6 曜日 6 evaltext $@ evalエラー 7 size 7 年の日数 7 is_require $$ プロセスID 8 atime 8 夏時間か 8 hints $. 行番号 9 mtime 9 bitmask @ARGV コマンドライン引数 10 ctime 10 hinthash @INC インクルードパス 11 blksz 3..9はEXPR @_ サブルーチン引数 12 blcks の時だけ %ENV 環境変数 =head1 ACKNOWLEDGEMENTS =begin original The first version of this document appeared on Perl Monks, where several people had useful suggestions. Thank you, Perl Monks. =end original この文書の最初のバージョンは Perl Monks に現れ、何人かから有用な 提案を頂きました。 Perl Monks、ありがとう。 =begin original A special thanks to Damian Conway, who didn't only suggest important changes, but also took the time to count the number of listed features and make a Perl 6 version to show that Perl will stay Perl. =end original 重要な変更を提案してくれただけでなく、いくつの機能が載っているかを 数えてくれ、Perl が Perl のままであることを示すために Perl 6 版を 作ってくれた Damian Conway に特に感謝します。 =head1 AUTHOR Juerd Waalboer <#####@juerd.nl>, with the help of many Perl Monks. =head1 SEE ALSO =over 4 =item * L - the original PM post =item * L - Damian Conway's Perl 6 version =item * L - home of the Perl Cheat Sheet =back =begin meta Translate: SHIRAKATA Kentaro Status: completed =end meta