#!/usr/bin/perl -w my @strictures; BEGIN { require strict; if( ! grep /-v/, @ARGV ) { @strictures= "refs"; } } use strict @strictures; sub name1() { return "Foo::Bar" } sub name2 { return "Foo::Bar" } "Foo::Bar"->{key}= "value"; # No error print name1->{key},$/; # No error, prints "value" eval { print name2->{key},$/ # Fatal run-time error # Can't use string ("Foo::Bar") as a HASH ref while "strict refs" } or warn $@; { package Foo::Bar; print __PACKAGE__->{key},$/; # No error, prints "value" } eval q{ sub name3() { return "Foo" } sub name4 { return "Foo" } "Foo"->{key}= "bar"; # If only strict 'refs', then prints "bar" w/ no errors # (-v)Global symbol "%Foo" requires explicit package name print name3->{key},$/; # If only strict 'refs', then prints "bar" w/ no errors # (-v)Global symbol "%Foo" requires explicit package name eval { print name4->{key},$/; # Can't use string ("Foo") as a HASH ref while "strict refs" } or warn "Line ",__LINE__,": $@"; eval q{ package Foo; print __PACKAGE__->{key},$/; # Use of uninitialized value in print 1; } or warn "Line ",__LINE__,": $@"; } or warn "Line ",__LINE__,": $@"; #### perl -MO=Deparse -e "'Foo'->{key}= 'value'" $Foo{'key'} = 'value'; -e syntax OK