Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Globals, localisation and strict.

by jarich (Curate)
on Jan 09, 2002 at 06:14 UTC ( [id://137347]=note: print w/replies, xml ) Need Help??

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
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://137347]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-23 12:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found