Check strict refs functionality __END__ # no strict, should build & run ok. my $fred ; $b = "fred" ; $a = $$b ; $c = ${"def"} ; $c = @{"def"} ; $c = %{"def"} ; $c = *{"def"} ; $c = \&{"def"} ; $c = def->[0]; $c = def->{xyz}; EXPECT ######## # strict refs - error use strict ; my $str="A::Really::Big::Package::Name::To::Use"; $str->{foo}= 1; EXPECT Can't use string ("A::Really::Big::Package::Name::T"...) as a HASH ref while "strict refs" in use at - line 5. ######## # strict refs - error use strict ; my $fred ; my $a = ${"fred"} ; EXPECT Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 5. ######## # strict refs - error use strict 'refs' ; my $fred ; my $a = ${"fred"} ; EXPECT Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 5. ######## # strict refs - error use strict 'refs' ; my $fred ; my $b = "fred" ; my $a = $$b ; EXPECT Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 6. ######## # strict refs - error use strict 'refs' ; my $b ; my $a = $$b ; EXPECT Can't use an undefined value as a SCALAR reference at - line 5. ######## # strict refs - error use strict 'refs' ; my $b ; my $a = @$b ; EXPECT Can't use an undefined value as an ARRAY reference at - line 5. ######## # strict refs - error use strict 'refs' ; my $b ; my $a = %$b ; EXPECT Can't use an undefined value as a HASH reference at - line 5. ######## # strict refs - error use strict 'refs' ; my $b ; my $a = *$b ; EXPECT Can't use an undefined value as a symbol reference at - line 5. ######## # strict refs - error use strict 'refs' ; my $a = fred->[0] ; EXPECT Can't use bareword ("fred") as an ARRAY ref while "strict refs" in use at - line 4. ######## # strict refs - error use strict 'refs' ; my $a = fred->{barney} ; EXPECT Can't use bareword ("fred") as a HASH ref while "strict refs" in use at - line 4. ######## # strict refs - no error use strict ; no strict 'refs' ; my $fred ; my $b = "fred" ; my $a = $$b ; use strict 'refs' ; EXPECT ######## # strict refs - no error use strict qw(subs vars) ; my $fred ; my $b = "fred" ; my $a = $$b ; use strict 'refs' ; EXPECT ######## # strict refs - no error my $fred ; my $b = "fred" ; my $a = $$b ; use strict 'refs' ; EXPECT ######## # strict refs - no error use strict 'refs' ; my $fred ; my $b = \$fred ; my $a = $$b ; EXPECT ######## # Check runtime scope of strict refs pragma use strict 'refs'; my $fred ; my $b = "fred" ; { no strict ; my $a = $$b ; } my $a = $$b ; EXPECT Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 10. ######## # Check runtime scope of strict refs pragma no strict ; my $fred ; my $b = "fred" ; { use strict 'refs' ; my $a = $$b ; } my $a = $$b ; EXPECT Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. ######## # Check runtime scope of strict refs pragma no strict ; my $fred ; my $b = "fred" ; { use strict 'refs' ; $a = sub { my $c = $$b ; } } &$a ; EXPECT Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. ######## --FILE-- abc my $a = ${"Fred"} ; 1; --FILE-- use strict 'refs' ; require "./abc"; EXPECT ######## --FILE-- abc use strict 'refs' ; 1; --FILE-- require "./abc"; my $a = ${"Fred"} ; EXPECT ######## --FILE-- abc use strict 'refs' ; my $a = ${"Fred"} ; 1; --FILE-- ${"Fred"} ; require "./abc"; EXPECT Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at ./abc line 2. Compilation failed in require at - line 2. ######## --FILE-- abc.pm use strict 'refs' ; my $a = ${"Fred"} ; 1; --FILE-- my $a = ${"Fred"} ; use abc; EXPECT Can't use string ("Fred") as a SCALAR ref while "strict refs" 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 eval no strict ; eval { my $a = ${"Fred"} ; }; print STDERR $@ ; my $a = ${"Fred"} ; EXPECT ######## # Check scope of pragma with eval no strict ; eval { use strict 'refs' ; my $a = ${"Fred"} ; }; print STDERR $@ ; my $a = ${"Fred"} ; EXPECT Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 6. ######## # Check scope of pragma with eval use strict 'refs' ; eval { my $a = ${"Fred"} ; }; print STDERR $@ ; EXPECT Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 5. ######## # Check scope of pragma with eval use strict 'refs' ; eval { no strict ; my $a = ${"Fred"} ; }; print STDERR $@ ; my $a = ${"Fred"} ; EXPECT Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 9. ######## # Check scope of pragma with eval no strict ; eval ' my $a = ${"Fred"} ; '; print STDERR $@ ; my $a = ${"Fred"} ; EXPECT ######## # Check scope of pragma with eval no strict ; eval q[ use strict 'refs' ; my $a = ${"Fred"} ; ]; print STDERR $@; EXPECT Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 3. ######## # Check scope of pragma with eval use strict 'refs' ; eval ' my $a = ${"Fred"} ; '; print STDERR $@ ; EXPECT Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 2. ######## # Check scope of pragma with eval use strict 'refs' ; eval ' no strict ; my $a = ${"Fred"} ; '; print STDERR $@; my $a = ${"Fred"} ; EXPECT Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 8. ######## # [perl #26910] hints not propagated into (?{...}) use strict 'refs'; /(?{${"foo"}++})/; EXPECT Can't use string ("foo") as a SCALAR ref while "strict refs" in use at (re_eval 1) line 1. ######## # [perl #37886] strict 'refs' doesn't apply inside defined use strict 'refs'; my $x = "foo"; defined $$x; EXPECT Can't use string ("foo") as a SCALAR ref while "strict refs" in use at - line 4. ######## # [perl #37886] strict 'refs' doesn't apply inside defined use strict 'refs'; my $x = "foo"; defined @$x; EXPECT defined(@array) is deprecated at - line 4. (Maybe you should just omit the defined()?) Can't use string ("foo") as an ARRAY ref while "strict refs" in use at - line 4. ######## # [perl #37886] strict 'refs' doesn't apply inside defined use strict 'refs'; my $x = "foo"; defined %$x; EXPECT defined(%hash) is deprecated at - line 4. (Maybe you should just omit the defined()?) Can't use string ("foo") as a HASH ref while "strict refs" in use at - line 4. ######## # [perl #74168] Assertion failed: (SvTYPE(_svcur) >= SVt_PV), function Perl_softref2xv, file pp.c, line 240. use strict 'refs'; my $o = 1 ; $o->{1} ; EXPECT Can't use string ("1") as a HASH ref while "strict refs" in use at - line 3. ######## # pp_hot.c [pp_entersub] use strict 'refs'; use utf8; use open qw( :utf8 :std ); &{"F"}; EXPECT Can't use string ("F") as a subroutine ref while "strict refs" in use at - line 5.