use strict; $global = 1; #### # globals to our package. use vars qw/$global1 $global2 $fred/; our ($global1, $global2, $fred); #### use strict; package Fred; our $name = "John"; package Main; my $name = "Fred"; print $Fred::name; # prints "John"; print $name; # prints "Fred"; #### use strict; $::database = "backup"; # global variable in Main # package. package Fred; print $::database; # prints "backup"; #### #!/usr/local/bin/perl -w use strict; my $fred = 3; # accessible from here to end # of file/package. { my $fred = 2; # overrides previous $fred until # end of block print $fred; # prints "2"; } print $fred; # prints "3" #### use strict; my @array = qw/this is a sentence/; { local $, = " "; # changes $, to " ". Using # "my" with a Perl special # variable generates a compile # time error. print @array; # prints "this is a sentence" } print @array; # prints "thisisasentence" #### use strict; my $foo = "bar"; local $foo = 2; # will break. # although { local $foo = 2; # will be fine. } #### use strict; package Foo; my $foo = 12; package Bar; print $Foo::foo; # this won't work