Help for this page

Select Code to Download


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