Help for this page

Select Code to Download


  1. or download this
    my $test1 = 1;
    {
    ...
        print " Inside:  test1 = [$test1]  test2 = [$test2]\n";
    }
    print "Outside:  test1 = [$test1]  test2 = [$test2]\n";
    
  2. or download this
    D:\PerlMonks>scope1-fail.pl
     Inside:  test1 = [1]  test2 = [2]
    Outside:  test1 = [1]  test2 = []
    
    D:\PerlMonks>
    
  3. or download this
    
    
    <--- $test2 is blank!
    
  4. or download this
    use strict;
    
    ...
        print " Inside:  test1 = [$test1]  test2 = [$test2]\n";
    }
    print "Outside:  test1 = [$test1]  test2 = [$test2]\n";
    
  5. 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>
    
  6. or download this
    use strict;
    
    ...
        print " Inside:  test1 = [$test1]  test2 = [$test2]\n";
    }
    print "Outside:  test1 = [$test1]  test2 = [$test2]\n";
    
  7. or download this
    D:\PerlMonks>scope3-fail.pl
     Inside:  test1 = [1]  test2 = [2]
    Outside:  test1 = [1]  test2 = []
    
    D:\PerlMonks>
    
  8. or download this
    
    
    <--- $test2 is still blank!
    
  9. or download this
    use strict;
    use warnings;
    ...
        print " Inside:  test1 = [$test1]  test2 = [$test2]\n";
    }
    print "Outside:  test1 = [$test1]  test2 = [$test2]\n";
    
  10. or download this
    D:\PerlMonks>scope4-fail.pl
     Inside:  test1 = [1]  test2 = [2]
    ...
    Outside:  test1 = [1]  test2 = []
    
    D:\PerlMonks>
    
  11. or download this
    use strict;
    use warnings;
    ...
    
    exit;
    __END__
    
  12. or download this
    D:\PerlMonks>scope5-win.pl
     Inside:  test1 = [1]  test2 = [2]
    Outside:  test1 = [1]  test2 = [2]
    
    D:\PerlMonks>