=encoding euc-jp =head1 NAME strict - 安全ではないコンストラクトを制限する Perl プラグマ =head1 SYNOPSIS use strict; use strict "vars"; use strict "refs"; use strict "subs"; use strict; no strict "vars"; =head1 DESCRIPTION If no import list is supplied, all possible restrictions are assumed. (This is the safest mode to operate in, but is sometimes too strict for casual programming.) Currently, there are three possible things to be strict about: "subs", "vars", and "refs". インポートリストを与えない場合は、可能な限り全ての制約を受けます。 (これは、最も安全な動作モードです。ただ、カジュアルプログラミング のためには厳しすぎます。)今のところ、"subs"、"vars"、"refs" の 3つの制約が用意されています。 =over 6 =item C This generates a runtime error if you use symbolic references (see L). シンボリックリファレンスが使われたときにランタイムエラーになります。 (L を見てください。) use strict 'refs'; $ref = \$foo; print $$ref; # ok $ref = "foo"; print $$ref; # ランタイムエラー; 普段は ok $file = "STDOUT"; print $file "Hi!"; # エラー; note: $file の後にコンマがない。 There is one exception to this rule: このルールには 1つの例外があります。 $bar = \&{'foo'}; &$bar; is allowed so that C would not break under stricture. 上記のものは許容されます。だから C はこの制約下でも 動きます。 =item C This generates a compile-time error if you access a variable that wasn't declared via "our" or C, localized via C, or wasn't fully qualified. Because this is to avoid variable suicide problems and subtle dynamic scoping issues, a merely local() variable isn't good enough. See L and L. "our" や C、C で宣言された変数や完全に修飾された 変数以外にアクセスしたときにコンパイル時エラーを出します。 変数が自殺してしまう問題や微表な動的スコープの問題があるため、 local() 変数だけでは十分ではありません。L や L を見てください。 use strict 'vars'; $X::foo = 1; # ok, 完全に修飾されています my $foo = 10; # ok, my() 変数 local $foo = 9; # ダメ package Cinna; our $bar; # パッケージ内で宣言された $bar $bar = 'HgS'; # ok, プラグマでグローバルに宣言された The local() generated a compile-time error because you just touched a global name without fully qualifying it. local() は、完全な修飾無しにグローバルな名前を触ってしまうため コンパイル時エラーを出します。 Because of their special use by sort(), the variables $a and $b are exempted from this check. sort() によって使われるという理由で $a と $b はこのチェックの 適用外という特別扱いになっています。 =item C This disables the poetry optimization, generating a compile-time error if you try to use a bareword identifier that's not a subroutine, unless it appears in curly braces or on the left hand side of the "=E" symbol. 詩的な最適化を禁止し、サブルーチン以外の裸の識別子を使おうとしたときか、 中括弧の中や "=E" シンボルの左側に無いときにコンパイル時エラーを出します。 use strict 'subs'; $SIG{PIPE} = Plumber; # ダメ $SIG{PIPE} = "Plumber"; # 問題なし: 中括弧の中ならいつでも裸で ok $SIG{PIPE} = \&Plumber; # 好ましい方法 =back See L. L を見てください。 =cut