1Check strict refs functionality 2 3__END__ 4 5# no strict, should build & run ok. 6my $fred ; 7$b = "fred" ; 8$a = $$b ; 9$c = ${"def"} ; 10$c = @{"def"} ; 11$c = %{"def"} ; 12$c = *{"def"} ; 13$c = \&{"def"} ; 14$c = def->[0]; 15$c = def->{xyz}; 16EXPECT 17 18######## 19 20# strict refs - error 21use strict ; 22my $str="A::Really::Big::Package::Name::To::Use"; 23$str->{foo}= 1; 24EXPECT 25Can't use string ("A::Really::Big::Package::Name::T"...) as a HASH ref while "strict refs" in use at - line 5. 26######## 27 28# strict refs - error 29use strict ; 30my $fred ; 31my $a = ${"fred"} ; 32EXPECT 33Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 5. 34######## 35 36# strict refs - error 37use strict 'refs' ; 38my $fred ; 39my $a = ${"fred"} ; 40EXPECT 41Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 5. 42######## 43 44# strict refs - error 45use strict 'refs' ; 46my $fred ; 47my $b = "fred" ; 48my $a = $$b ; 49EXPECT 50Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 6. 51######## 52 53# strict refs - error 54use strict 'refs' ; 55my $b ; 56my $a = $$b ; 57EXPECT 58Can't use an undefined value as a SCALAR reference at - line 5. 59######## 60 61# strict refs - error 62use strict 'refs' ; 63my $b ; 64my $a = @$b ; 65EXPECT 66Can't use an undefined value as an ARRAY reference at - line 5. 67######## 68 69# strict refs - error 70use strict 'refs' ; 71my $b ; 72my $a = %$b ; 73EXPECT 74Can't use an undefined value as a HASH reference at - line 5. 75######## 76 77# strict refs - error 78use strict 'refs' ; 79my $b ; 80my $a = *$b ; 81EXPECT 82Can't use an undefined value as a symbol reference at - line 5. 83######## 84 85# strict refs - error 86use strict 'refs' ; 87my $a = fred->[0] ; 88EXPECT 89Can't use bareword ("fred") as an ARRAY ref while "strict refs" in use at - line 4. 90######## 91 92# strict refs - error 93use strict 'refs' ; 94my $a = fred->{barney} ; 95EXPECT 96Can't use bareword ("fred") as a HASH ref while "strict refs" in use at - line 4. 97######## 98 99# strict refs - no error 100use strict ; 101no strict 'refs' ; 102my $fred ; 103my $b = "fred" ; 104my $a = $$b ; 105use strict 'refs' ; 106EXPECT 107 108######## 109 110# strict refs - no error 111use strict qw(subs vars) ; 112my $fred ; 113my $b = "fred" ; 114my $a = $$b ; 115use strict 'refs' ; 116EXPECT 117 118######## 119 120# strict refs - no error 121my $fred ; 122my $b = "fred" ; 123my $a = $$b ; 124use strict 'refs' ; 125EXPECT 126 127######## 128 129# strict refs - no error 130use strict 'refs' ; 131my $fred ; 132my $b = \$fred ; 133my $a = $$b ; 134EXPECT 135 136######## 137 138# Check runtime scope of strict refs pragma 139use strict 'refs'; 140my $fred ; 141my $b = "fred" ; 142{ 143 no strict ; 144 my $a = $$b ; 145} 146my $a = $$b ; 147EXPECT 148Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 10. 149######## 150 151# Check runtime scope of strict refs pragma 152no strict ; 153my $fred ; 154my $b = "fred" ; 155{ 156 use strict 'refs' ; 157 my $a = $$b ; 158} 159my $a = $$b ; 160EXPECT 161Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. 162######## 163 164# Check runtime scope of strict refs pragma 165no strict ; 166my $fred ; 167my $b = "fred" ; 168{ 169 use strict 'refs' ; 170 $a = sub { my $c = $$b ; } 171} 172&$a ; 173EXPECT 174Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. 175######## 176 177 178--FILE-- abc 179my $a = ${"Fred"} ; 1801; 181--FILE-- 182use strict 'refs' ; 183require "./abc"; 184EXPECT 185 186######## 187 188--FILE-- abc 189use strict 'refs' ; 1901; 191--FILE-- 192require "./abc"; 193my $a = ${"Fred"} ; 194EXPECT 195 196######## 197 198--FILE-- abc 199use strict 'refs' ; 200my $a = ${"Fred"} ; 2011; 202--FILE-- 203${"Fred"} ; 204require "./abc"; 205EXPECT 206Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at ./abc line 2. 207Compilation failed in require at - line 2. 208######## 209 210--FILE-- abc.pm 211use strict 'refs' ; 212my $a = ${"Fred"} ; 2131; 214--FILE-- 215my $a = ${"Fred"} ; 216use abc; 217EXPECT 218Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at abc.pm line 2. 219Compilation failed in require at - line 2. 220BEGIN failed--compilation aborted at - line 2. 221######## 222 223# Check scope of pragma with eval 224no strict ; 225eval { 226 my $a = ${"Fred"} ; 227}; 228print STDERR $@ ; 229my $a = ${"Fred"} ; 230EXPECT 231 232######## 233 234# Check scope of pragma with eval 235no strict ; 236eval { 237 use strict 'refs' ; 238 my $a = ${"Fred"} ; 239}; 240print STDERR $@ ; 241my $a = ${"Fred"} ; 242EXPECT 243Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 6. 244######## 245 246# Check scope of pragma with eval 247use strict 'refs' ; 248eval { 249 my $a = ${"Fred"} ; 250}; 251print STDERR $@ ; 252EXPECT 253Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 5. 254######## 255 256# Check scope of pragma with eval 257use strict 'refs' ; 258eval { 259 no strict ; 260 my $a = ${"Fred"} ; 261}; 262print STDERR $@ ; 263my $a = ${"Fred"} ; 264EXPECT 265Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 9. 266######## 267 268# Check scope of pragma with eval 269no strict ; 270eval ' 271 my $a = ${"Fred"} ; 272'; print STDERR $@ ; 273my $a = ${"Fred"} ; 274EXPECT 275 276######## 277 278# Check scope of pragma with eval 279no strict ; 280eval q[ 281 use strict 'refs' ; 282 my $a = ${"Fred"} ; 283]; print STDERR $@; 284EXPECT 285Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 3. 286######## 287 288# Check scope of pragma with eval 289use strict 'refs' ; 290eval ' 291 my $a = ${"Fred"} ; 292'; print STDERR $@ ; 293EXPECT 294Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 2. 295######## 296 297# Check scope of pragma with eval 298use strict 'refs' ; 299eval ' 300 no strict ; 301 my $a = ${"Fred"} ; 302'; print STDERR $@; 303my $a = ${"Fred"} ; 304EXPECT 305Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 8. 306######## 307# [perl #26910] hints not propagated into (?{...}) 308use strict 'refs'; 309/(?{${"foo"}++})/; 310EXPECT 311Can't use string ("foo") as a SCALAR ref while "strict refs" in use at (re_eval 1) line 1. 312######## 313# [perl #37886] strict 'refs' doesn't apply inside defined 314use strict 'refs'; 315my $x = "foo"; 316defined $$x; 317EXPECT 318Can't use string ("foo") as a SCALAR ref while "strict refs" in use at - line 4. 319######## 320# [perl #37886] strict 'refs' doesn't apply inside defined 321use strict 'refs'; 322my $x = "foo"; 323defined @$x; 324EXPECT 325defined(@array) is deprecated at - line 4. 326 (Maybe you should just omit the defined()?) 327Can't use string ("foo") as an ARRAY ref while "strict refs" in use at - line 4. 328######## 329# [perl #37886] strict 'refs' doesn't apply inside defined 330use strict 'refs'; 331my $x = "foo"; 332defined %$x; 333EXPECT 334defined(%hash) is deprecated at - line 4. 335 (Maybe you should just omit the defined()?) 336Can't use string ("foo") as a HASH ref while "strict refs" in use at - line 4. 337######## 338# [perl #74168] Assertion failed: (SvTYPE(_svcur) >= SVt_PV), function Perl_softref2xv, file pp.c, line 240. 339use strict 'refs'; 340my $o = 1 ; $o->{1} ; 341EXPECT 342Can't use string ("1") as a HASH ref while "strict refs" in use at - line 3. 343######## 344# pp_hot.c [pp_entersub] 345use strict 'refs'; 346use utf8; 347use open qw( :utf8 :std ); 348&{"F"}; 349EXPECT 350Can't use string ("F") as a subroutine ref while "strict refs" in use at - line 5. 351