📄 subs
字号:
Check strict subs functionality__END__# no strict, should build & run ok.Fred ;my $fred ;$b = "fred" ;$a = $$b ;EXPECT########use strict qw(refs vars);Fred ;EXPECT########use strict ;no strict 'subs' ;Fred ;EXPECT######### strict subs - erroruse strict 'subs' ;my @a = (1..2);my $b = xyz;EXPECTBareword "xyz" not allowed while "strict subs" in use at - line 5.Execution of - aborted due to compilation errors.######### strict subs - erroruse strict 'subs' ;Fred ;EXPECTBareword "Fred" not allowed while "strict subs" in use at - line 4.Execution of - aborted due to compilation errors.######### strict subs - erroruse strict 'subs' ;my @a = (A..Z);EXPECTBareword "Z" not allowed while "strict subs" in use at - line 4.Bareword "A" not allowed while "strict subs" in use at - line 4.Execution of - aborted due to compilation errors.######### strict subs - erroruse strict 'subs' ;my $a = (B..Y);EXPECTBareword "Y" not allowed while "strict subs" in use at - line 4.Bareword "B" not allowed while "strict subs" in use at - line 4.Execution of - aborted due to compilation errors.######### strict subs - erroruse strict ;Fred ;EXPECTBareword "Fred" not allowed while "strict subs" in use at - line 4.Execution of - aborted due to compilation errors.######### strict subs - no erroruse strict 'subs' ;sub Fred {}Fred ;EXPECT######### Check compile time scope of strict subs pragmause strict 'subs' ;{ no strict ; my $a = Fred ;}my $a = Fred ;EXPECTBareword "Fred" not allowed while "strict subs" in use at - line 8.Execution of - aborted due to compilation errors.######### Check compile time scope of strict subs pragmano strict;{ use strict 'subs' ; my $a = Fred ;}my $a = Fred ;EXPECTBareword "Fred" not allowed while "strict subs" in use at - line 6.Execution of - aborted due to compilation errors.######### Check compile time scope of strict vars pragmause strict 'vars' ;{ no strict ; $joe = 1 ;}$joe = 1 ;EXPECTVariable "$joe" is not imported at - line 8.Global symbol "$joe" requires explicit package name at - line 8.Execution of - aborted due to compilation errors.######### Check compile time scope of strict vars pragmano strict;{ use strict 'vars' ; $joe = 1 ;}$joe = 1 ;EXPECTGlobal symbol "$joe" requires explicit package name at - line 6.Execution of - aborted due to compilation errors.######### Check runtime scope of strict refs pragmause strict 'refs';my $fred ;my $b = "fred" ;{ no strict ; my $a = $$b ;}my $a = $$b ;EXPECTCan't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 10.######### Check runtime scope of strict refs pragmano strict ;my $fred ;my $b = "fred" ;{ use strict 'refs' ; my $a = $$b ;}my $a = $$b ;EXPECTCan't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8.######### Check runtime scope of strict refs pragmano strict ;my $fred ;my $b = "fred" ;{ use strict 'refs' ; $a = sub { my $c = $$b ; }}&$a ;EXPECTCan't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8.########use strict 'subs' ;my $a = Fred ;EXPECTBareword "Fred" not allowed while "strict subs" in use at - line 3.Execution of - aborted due to compilation errors.########--FILE-- abcmy $a = Fred ;1;--FILE-- use strict 'subs' ;require "./abc";EXPECT########--FILE-- abcuse strict 'subs' ;1;--FILE-- require "./abc";my $a = Fred ;EXPECT########--FILE-- abcuse strict 'subs' ;my $a = Fred ;1;--FILE-- Fred ;require "./abc";EXPECTBareword "Fred" not allowed while "strict subs" in use at ./abc line 2.Compilation failed in require at - line 2.########--FILE-- abc.pmuse strict 'subs' ;my $a = Fred ;1;--FILE-- Fred ;use abc;EXPECTBareword "Fred" not allowed while "strict subs" in use at abc.pm line 2.Compilation failed in require at - line 2.BEGIN failed--compilation aborted at - line 2.######### Check scope of pragma with evalno strict ;eval { my $a = Fred ;};print STDERR $@;my $a = Fred ;EXPECT######### Check scope of pragma with evalno strict ;eval { use strict 'subs' ; my $a = Fred ;};print STDERR $@;my $a = Fred ;EXPECTBareword "Fred" not allowed while "strict subs" in use at - line 6.Execution of - aborted due to compilation errors.######### Check scope of pragma with evaluse strict 'subs' ;eval { my $a = Fred ;};print STDERR $@;my $a = Fred ;EXPECTBareword "Fred" not allowed while "strict subs" in use at - line 5.Bareword "Fred" not allowed while "strict subs" in use at - line 8.Execution of - aborted due to compilation errors.######### Check scope of pragma with evaluse strict 'subs' ;eval { no strict ; my $a = Fred ;};print STDERR $@;my $a = Fred ;EXPECTBareword "Fred" not allowed while "strict subs" in use at - line 9.Execution of - aborted due to compilation errors.######### Check scope of pragma with evalno strict ;eval ' Fred ;'; print STDERR $@ ;Fred ;EXPECT######### Check scope of pragma with evalno strict ;eval q[ use strict 'subs' ; Fred ;]; print STDERR $@;EXPECTBareword "Fred" not allowed while "strict subs" in use at (eval 1) line 3.######### Check scope of pragma with evaluse strict 'subs' ;eval ' Fred ;'; print STDERR $@ ;EXPECTBareword "Fred" not allowed while "strict subs" in use at (eval 1) line 2.######### Check scope of pragma with evaluse strict 'subs' ;eval ' no strict ; my $a = Fred ;'; print STDERR $@;my $a = Fred ;EXPECTBareword "Fred" not allowed while "strict subs" in use at - line 8.Execution of - aborted due to compilation errors.######### see if Foo->Bar(...) etc work under stricturesuse strict;package Foo; sub Bar { print "@_\n" }Foo->Bar('a',1);Bar Foo ('b',2);Foo->Bar(qw/c 3/);Bar Foo (qw/d 4/);Foo::->Bar('A',1);Bar Foo:: ('B',2);Foo::->Bar(qw/C 3/);Bar Foo:: (qw/D 4/);EXPECTFoo a 1Foo b 2Foo c 3Foo d 4Foo A 1Foo B 2Foo C 3Foo D 4######### Check that barewords on the RHS of a regex match are caughtuse strict;"" =~ foo;EXPECTBareword "foo" not allowed while "strict subs" in use at - line 4.Execution of - aborted due to compilation errors.######### ID 20020703.002use strict;use warnings;my $abc = XYZ ? 1 : 0;print "$abc\n";EXPECTBareword "XYZ" not allowed while "strict subs" in use at - line 5.Execution of - aborted due to compilation errors.######### [perl #10021]use strict;use warnings;print "" if BAREWORD;EXPECTBareword "BAREWORD" not allowed while "strict subs" in use at - line 5.Execution of - aborted due to compilation errors.######### Ticket: 18927use strict 'subs';print 1..1, bad;EXPECTBareword "bad" not allowed while "strict subs" in use at - line 3.Execution of - aborted due to compilation errors.########eval q{ use strict; no strict refs; };print $@;EXPECTBareword "refs" not allowed while "strict subs" in use at (eval 1) line 1.######### [perl #25147] use strict;print "" if BAREWORD;EXPECTBareword "BAREWORD" not allowed while "strict subs" in use at - line 3.Execution of - aborted due to compilation errors.######### [perl #26910] hints not propagated into (?{...})use strict 'subs';qr/(?{my $x=foo})/;EXPECTBareword "foo" not allowed while "strict subs" in use at (re_eval 1) line 1.Compilation failed in regexp at - line 3.######### [perl #27628] strict 'subs' didn't warn on bareword array indexuse strict 'subs';my $x=$a[FOO];EXPECTBareword "FOO" not allowed while "strict subs" in use at - line 3.Execution of - aborted due to compilation errors.########use strict 'subs';my @a;my $x=$a[FOO];EXPECTBareword "FOO" not allowed while "strict subs" in use at - line 2.Execution of - aborted due to compilation errors.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -