- or download this
use strict;
$global = 1;
- or download this
# globals to our package.
use vars qw/$global1 $global2 $fred/;
our ($global1, $global2, $fred);
- or download this
use strict;
package Fred;
our $name = "John";
...
my $name = "Fred";
print $Fred::name; # prints "John";
print $name; # prints "Fred";
- or download this
use strict;
$::database = "backup"; # global variable in Main
...
# package.
package Fred;
print $::database; # prints "backup";
- or download this
#!/usr/local/bin/perl -w
use strict;
...
print $fred; # prints "2";
}
print $fred; # prints "3"
- or download this
use strict;
my @array = qw/this is a sentence/;
...
print @array; # prints "this is a sentence"
}
print @array; # prints "thisisasentence"
- or download this
use strict;
my $foo = "bar";
...
{
local $foo = 2; # will be fine.
}
- or download this
use strict;
package Foo;
...
package Bar;
print $Foo::foo; # this won't work