- or download this
my $test1 = 1;
{
...
print " Inside: test1 = [$test1] test2 = [$test2]\n";
}
print "Outside: test1 = [$test1] test2 = [$test2]\n";
- or download this
D:\PerlMonks>scope1-fail.pl
Inside: test1 = [1] test2 = [2]
Outside: test1 = [1] test2 = []
D:\PerlMonks>
- or download this
<--- $test2 is blank!
- or download this
use strict;
...
print " Inside: test1 = [$test1] test2 = [$test2]\n";
}
print "Outside: test1 = [$test1] test2 = [$test2]\n";
- or download this
D:\PerlMonks>scope2-fail.pl
Global symbol "$test2" requires explicit package name at D:\PerlMonks\
+scope2-fail.pl line 8.
Execution of D:\PerlMonks\scope2-fail.pl aborted due to compilation er
+rors.
D:\PerlMonks>
- or download this
use strict;
...
print " Inside: test1 = [$test1] test2 = [$test2]\n";
}
print "Outside: test1 = [$test1] test2 = [$test2]\n";
- or download this
D:\PerlMonks>scope3-fail.pl
Inside: test1 = [1] test2 = [2]
Outside: test1 = [1] test2 = []
D:\PerlMonks>
- or download this
<--- $test2 is still blank!
- or download this
use strict;
use warnings;
...
print " Inside: test1 = [$test1] test2 = [$test2]\n";
}
print "Outside: test1 = [$test1] test2 = [$test2]\n";
- or download this
D:\PerlMonks>scope4-fail.pl
Inside: test1 = [1] test2 = [2]
...
Outside: test1 = [1] test2 = []
D:\PerlMonks>
- or download this
use strict;
use warnings;
...
exit;
__END__
- or download this
D:\PerlMonks>scope5-win.pl
Inside: test1 = [1] test2 = [2]
Outside: test1 = [1] test2 = [2]
D:\PerlMonks>