Skip to content

Latest commit

 

History

History
121 lines (80 loc) · 3.45 KB

strict.pod

File metadata and controls

121 lines (80 loc) · 3.45 KB

NAME

strict - 絎������с�壔�ŝ����潟�潟�鴻����í�壔�������狗�������� Perl �����í�違��

SYNOPSIS

use strict;

use strict "vars";
use strict "refs";
use strict "subs";

use strict;
no strict "vars";

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��ゃ�勐�句�������������������⓾����障�����

strict refs

This generates a runtime error if you use symbolic references (see perlref).

��激�潟����ŝ����壔�ŝ����<�㋘�潟�鴻��篏帥����������������˨�í�潟�帥�ゃ�������í�若�˨�ŝ����障����� 鐚�perlref ���荀���⓾��������������鐚�

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 goto &$AUTOLOAD would not break under stricture.

筝�荐���勉����勉�虁┗絎鴻�������障�������������� goto &$AUTOLOAD ��壔����勐�句��筝���с�� ��������障�����

strict vars

This generates a compile-time error if you access a variable that wasn't declared via "our" or use vars, localized via my(), 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 "my" in perlfunc and "local" in perlfunc.

"our" ��� use vars���my() ��у㐂荐����������紊���違��絎������˩信蕋障�������� 紊���遺札紊���˨�≪�壔�祉�鴻�������������˨�潟�潟����ゃ����������í�若����冴����障����� 紊���違����ʋ俠�����⓾����障����馹����緇勤;��ɱ�������鴻�潟�若����勐�馹������������������� local() 紊���違�������с�壠�������с�壔�������障��������"my" in perlfunc ��� "local" in perlfunc ���荀���⓾��������������

use strict 'vars';
$X::foo = 1;     # ok, 絎������˩信蕋障�������⓾����障��
my $foo = 10;    # ok, my() 紊���
local $foo = 9;  # �����

package Cinna;
our $bar;                       # ��������宴�若�後����у㐂荐���������� $bar
$bar = 'HgS';           # ok, �����í�違����с�違�㏍�若����˨��絎h�����������

The local() generated a compile-time error because you just touched a global name without fully qualifying it.

local() ��壔��絎������ŭ信蕋丞�<����˨�違�㏍�若����˨�ɱ��������茹⓾�c�⓾����障�������� ��潟�潟����ゃ����������í�若����冴����障�����

Because of their special use by sort(), the variables $a and $b are exempted from this check.

sort() ��˨����c�☖戎�����������������������宴�� $a ��� $b ��壔����勉����с����壔� ��ñ��紊������������劫�ユ�宴����˨�ŝ�c�⓾����障�����

strict subs

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 "=>" symbol.

荅ñ����ʋ����ï�����胼�罩≪�������泣����˨�若����割札紊���勤8��勤����ュ�����篏帥�������������������������� 筝㊥�㋚磁��勌賢��� "=>" ��激�潟����˨�勐窪��眼�̥�<����������˨�潟�潟����ゃ����������í�若����冴����障�����

use strict 'subs';
$SIG{PIPE} = Plumber;           # �����
$SIG{PIPE} = "Plumber";         # ��馹���ŝ��: 筝㊥�㋚磁��勌賢��ŝ�������ゃ�с��茖吾�� ok
$SIG{PIPE} = \&Plumber;         # 絅純�障�������号��

See "Pragmatic Modules" in perlmodlib.

"Pragmatic Modules" in perlmodlib ���荀���⓾��������������