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 $fred ; 23my $a = ${"fred"} ; 24EXPECT 25Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 5. 26######## 27 28# strict refs - error 29use strict 'refs' ; 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 $b = "fred" ; 40my $a = $$b ; 41EXPECT 42Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 6. 43######## 44 45# strict refs - error 46use strict 'refs' ; 47my $b ; 48my $a = $$b ; 49EXPECT 50Can't use an undefined value as a SCALAR reference at - line 5. 51######## 52 53# strict refs - error 54use strict 'refs' ; 55my $b ; 56my $a = @$b ; 57EXPECT 58Can't use an undefined value as an ARRAY 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 a HASH 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 symbol reference at - line 5. 75######## 76 77# strict refs - error 78use strict 'refs' ; 79my $a = fred->[0] ; 80EXPECT 81Can't use bareword ("fred") as an ARRAY ref while "strict refs" in use at - line 4. 82######## 83 84# strict refs - error 85use strict 'refs' ; 86my $a = fred->{barney} ; 87EXPECT 88Can't use bareword ("fred") as a HASH ref while "strict refs" in use at - line 4. 89######## 90 91# strict refs - no error 92use strict ; 93no strict 'refs' ; 94my $fred ; 95my $b = "fred" ; 96my $a = $$b ; 97use strict 'refs' ; 98EXPECT 99 100######## 101 102# strict refs - no error 103use strict qw(subs vars) ; 104my $fred ; 105my $b = "fred" ; 106my $a = $$b ; 107use strict 'refs' ; 108EXPECT 109 110######## 111 112# strict refs - no error 113my $fred ; 114my $b = "fred" ; 115my $a = $$b ; 116use strict 'refs' ; 117EXPECT 118 119######## 120 121# strict refs - no error 122use strict 'refs' ; 123my $fred ; 124my $b = \$fred ; 125my $a = $$b ; 126EXPECT 127 128######## 129 130# Check runtime scope of strict refs pragma 131use strict 'refs'; 132my $fred ; 133my $b = "fred" ; 134{ 135 no strict ; 136 my $a = $$b ; 137} 138my $a = $$b ; 139EXPECT 140Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 10. 141######## 142 143# Check runtime scope of strict refs pragma 144no strict ; 145my $fred ; 146my $b = "fred" ; 147{ 148 use strict 'refs' ; 149 my $a = $$b ; 150} 151my $a = $$b ; 152EXPECT 153Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. 154######## 155 156# Check runtime scope of strict refs pragma 157no strict ; 158my $fred ; 159my $b = "fred" ; 160{ 161 use strict 'refs' ; 162 $a = sub { my $c = $$b ; } 163} 164&$a ; 165EXPECT 166Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. 167######## 168 169 170--FILE-- abc 171my $a = ${"Fred"} ; 1721; 173--FILE-- 174use strict 'refs' ; 175require "./abc"; 176EXPECT 177 178######## 179 180--FILE-- abc 181use strict 'refs' ; 1821; 183--FILE-- 184require "./abc"; 185my $a = ${"Fred"} ; 186EXPECT 187 188######## 189 190--FILE-- abc 191use strict 'refs' ; 192my $a = ${"Fred"} ; 1931; 194--FILE-- 195${"Fred"} ; 196require "./abc"; 197EXPECT 198Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at ./abc line 2. 199Compilation failed in require at - line 2. 200######## 201 202--FILE-- abc.pm 203use strict 'refs' ; 204my $a = ${"Fred"} ; 2051; 206--FILE-- 207my $a = ${"Fred"} ; 208use abc; 209EXPECT 210Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at abc.pm line 2. 211Compilation failed in require at - line 2. 212BEGIN failed--compilation aborted at - line 2. 213######## 214 215# Check scope of pragma with eval 216no strict ; 217eval { 218 my $a = ${"Fred"} ; 219}; 220print STDERR $@ ; 221my $a = ${"Fred"} ; 222EXPECT 223 224######## 225 226# Check scope of pragma with eval 227no strict ; 228eval { 229 use strict 'refs' ; 230 my $a = ${"Fred"} ; 231}; 232print STDERR $@ ; 233my $a = ${"Fred"} ; 234EXPECT 235Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 6. 236######## 237 238# Check scope of pragma with eval 239use strict 'refs' ; 240eval { 241 my $a = ${"Fred"} ; 242}; 243print STDERR $@ ; 244EXPECT 245Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 5. 246######## 247 248# Check scope of pragma with eval 249use strict 'refs' ; 250eval { 251 no strict ; 252 my $a = ${"Fred"} ; 253}; 254print STDERR $@ ; 255my $a = ${"Fred"} ; 256EXPECT 257Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 9. 258######## 259 260# Check scope of pragma with eval 261no strict ; 262eval ' 263 my $a = ${"Fred"} ; 264'; print STDERR $@ ; 265my $a = ${"Fred"} ; 266EXPECT 267 268######## 269 270# Check scope of pragma with eval 271no strict ; 272eval q[ 273 use strict 'refs' ; 274 my $a = ${"Fred"} ; 275]; print STDERR $@; 276EXPECT 277Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 3. 278######## 279 280# Check scope of pragma with eval 281use strict 'refs' ; 282eval ' 283 my $a = ${"Fred"} ; 284'; print STDERR $@ ; 285EXPECT 286Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 2. 287######## 288 289# Check scope of pragma with eval 290use strict 'refs' ; 291eval ' 292 no strict ; 293 my $a = ${"Fred"} ; 294'; print STDERR $@; 295my $a = ${"Fred"} ; 296EXPECT 297Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 8. 298######## 299# [perl #26910] hints not propagated into (?{...}) 300use strict 'refs'; 301/(?{${"foo"}++})/; 302EXPECT 303Can't use string ("foo") as a SCALAR ref while "strict refs" in use at (re_eval 1) line 1. 304