Local variable shadows the global variable in a subroutine : Local « Subroutine « Perl






Local variable shadows the global variable in a subroutine

   

#!/usr/bin/perl -w

$x = 10;

print "before: $x\n";
change_global_not();
print "after:  $x\n";

sub change_global_not {
    my $x = 20;
    print "in change_global_not(): $x\n";
}

   
    
    
  








Related examples in the same category

1.Local variable shadows the gloabl variable
2.Local variables in subroutines
3.Difference between my and local
4.Duplicate global and local variable name (use strict;)
5.Using local