Creates a global variable $myvar and prints out the global instance of the variable and the package-specific variable: : Variable Scope « Language Basics « Perl






Creates a global variable $myvar and prints out the global instance of the variable and the package-specific variable:

    

    #!/usr/local/bin/perl -w

    # Define a variable.
    $myvar = "Hello";

    # Print out the global variable.
    print "Global  : $myvar \n";

    # Print out the package specific variable.
    print "Specific: $main::myvar \n";

   
    
    
    
  








Related examples in the same category

1.Auto local variable
2.Local element
3.Local variables.
4.Forward Reference
5.Uses the same name inside and outside a foreach statement.
6.Scope of Variables: Variables used in subroutines are global by default