Brutal critique enclosed... beware, I get right to the point. :)
>>>>> "Me" == Me <[EMAIL PROTECTED]> writes:
Me> Unless you declare a name as being in some other
Me> package, a name is assumed to be in the main package:
Me> $_ = 1;
Me> # $_ is in main.
$_ is always in main, even if the current package is something else.
Me> Amazingly, a huge number of high quality packages
Me> are available publically for free in one nice big catalog
Me> called CPAN. Some come with perl as standard.
Me> Others need to be pulled in from the Internet. You can
Me> browse and search CPAN using a web browser:
Me> http://search.cpan.org/
Me> More on this in a footnote**.
That'd be "modules", not "packages". A package is a mechanism for
carving up the symbol-table (global) namespace. A module is a
reusable chunk of code. A module almost certainly uses a package, but
a package doesn't have to be a module. Or, package is to module what
gas is to a car. Best not to confuse the two.
Me> --------------
Me> Apart from main and MY, all other packages have to be
Me> given a name.
"main" is a name! "MY" is not a package.
Me> To use another package written by someone else,
Me> you write something like:
Me> use File::Copy;
module!
Me> Fortunately, the 'use File::Copy' statement does more
Me> than make the namespace available. It also imports
Me> some names right in to your main package.
Actually, the current package.
Me> If you are writing more than a one liner, you should
Me> start your scripts with:
Me> #!/usr/bin/perl
Me> use warnings;
Me> use strict;
use warnings makes your program needlessly incompatible with 5.5.
don't do that unless you're also using other 5.6 features.
Me> As already stated, most of the names you come up
Me> with will refer to things that are, well, yours, so you
Me> typically write things like:
Me> my $foo;
Me> so that $foo now belongs in the MY package.
$foo is now a lexical, not part of any package, and has a scope and
persistence related to where it is defined, no longer a global.
Me> package Foo;
Me> our $bar = 1; # set $bar from package Foo.
Me> our $baz = 2; # set $baz from package Foo.
"our" is 5.6, again needlessly incompatible with 5.5. "use vars qw($bar)"
is the close equivalent for all.
Me> If you redeclare a my, you throw away the old value:
Me> my $foo = 1;
Me> my $foo;
Me> # $foo is undefined.
This is almost certainly unintended, and merits a warning when
warnings are enabled.
Me> Only use local if you can't do what you want with my.
You haven't even mentioned what local is, so it doesn't even suggest
why you'd want this.
Me> * In Perl 5, the package I call MY package is not often
Me> called a package and can't be accessed in the same
Me> way that other packages can be accessed. However,
Me> in Perl 6, there will be a MY package, and, imo, it is
Me> simpler to use the term package for all namespaces.
This is news to me.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!