Uses the same name inside and outside a foreach statement. : Variable Scope « Language Basics « Perl






Uses the same name inside and outside a foreach statement.

    

#!/usr/local/bin/perl 

$temp = 1; 
@list = ("This", "is", "a", "list", "of", "words"); 
print ("Here are the words in the list: \n"); 
foreach $temp (@list) { 
    print ("$temp "); 
} 
print("\n"); 
print("The value of temp is now $temp\n"); 

   
    
    
    
  








Related examples in the same category

1.Auto local variable
2.Local element
3.Local variables.
4.Forward Reference
5.Creates a global variable $myvar and prints out the global instance of the variable and the package-specific variable:
6.Scope of Variables: Variables used in subroutines are global by default