HOW-TO of the Month Club (end Of MARCH Edition)
(Even though many of you *flamed* me - _I'mmmm baaaack_ :)
I didn't catch that thread, so I don't know why you were flamed, but I see no problem with posting occasional HOW-TOs so long as they are correct.
Suggestions: 1) start each HOW-TO subject with a constant string so they are easy to find, and 2) archive them on a web site and reference that link in each message.
This edition I will show you how to declare variables WITHOUT using *my* $var everywhere...
#! perl -Tw use strict; use warnings;
# get execution name $::prog = $0; # clean off directory portion $::prog =~ s|.*/||;
<pedantic>You would do better to use File::Basename here for portability</pedantic>
print "You ran $::prog! Good job!\n";
$:: syntax brings these variabkes into the current program - which is always $main::
The two methods are not equivelant. 'my' creates a lexical variable and 'our', 'use vars', and 'local' deal with package variables. Generally lexical variables should be preferred over package variables.
A good HOW-TO might talk about the differences between lexical and package variables and when to use each.
Regards, Randy.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>