[Wtr-general] Global Variables
Chris McMahon
christopher.mcmahon at gmail.com
Fri Sep 1 17:42:45 EDT 2006
> A local variable at "top level" in Python had the same
> context whether in the shell, in the current file being executed or in
> another file being loaded. These are all different contexts in Ruby, and
> i try to encourage testers early on to be able to trust that code
> executed in any of these ways will do the same thing, but this is only
> true of they use global variables.
Perl forces you to understand scope of variables fairly early (unless you
write bad Perl using package variables, not lexical variables, and don't use
warnings and don't use strictures, in which case you can ignore everything
that follows): unless you declare variables' scope the first time the
variable is used, the compiler gives you a warning. Variables declared
within a routine with "my $var" are available only to that routine;
variables declared outside routines with "my $var" are available to all
subroutines declared in that scope.
Global variables are designated by "our", not "my". "our $var" is available
to all routines in the program.
Managing this sometimes gets tricky. One of the most popular Perl FAQs of
all time is "Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20060901/91369a13/attachment.html
More information about the Wtr-general
mailing list