strict - Perl pragma to restrict unsafe constructs
use strict;
use strict "vars"; use strict "refs"; use strict "subs";
use strict; no strict "vars";
use strict 'refs'; $ref = \$foo; print $$ref; # ok $ref = "foo"; print $$ref; # runtime error; normally ok $file = "STDOUT"; print $file "Hi!"; # error; note: no comma after $file
There is one exception to this rule:
$bar = \&{'foo'}; &$bar;
is allowed so that "goto &$AUTOLOAD" would not break under stricture.
use strict 'vars'; $X::foo = 1; # ok, fully qualified my $foo = 10; # ok, my() var local $foo = 9; # blows up
package Cinna; our $bar; # Declares $bar in current package $bar = 'HgS'; # ok, global declared via pragma
The local() generated a compile-time error because you just touched a global name without fully qualifying it.
Because of their special use by sort(), the variables $a and $b are exempted from this check.
use strict 'subs'; $SIG{PIPE} = Plumber; # blows up $SIG{PIPE} = "Plumber"; # just fine: quoted string is always ok $SIG{PIPE} = \&Plumber; # preferred form
See ``Pragmatic Modules'' in perlmodlib.
Starting with Perl 5.8.1 strict is strict about its restrictions: if unknown restrictions are used, the strict pragma will abort with
Unknown 'strict' tag(s) '...'
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |