Re: my variable is recognized in following sub
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Wed, 26 Nov 2008 12:36:18 -0500
"x" == xhoster <xhoster@xxxxxxxxx> writes:
>> Why? You declared $a as a global variable.
x> Aren't global variables the same thing as package variables?
x> And aren't those mutually exclusive with lexical variables?
x> The scope of the lexical variable may be broad, but that doesn't
x> make it global, at least not in Perl vernacular as I understand it.
i have been watching this thread with bemusement and seeing the group
miscommunicate about this topic. let me try to clear up the mess. :)
if you declare a lexical (my) variable in the body of a perl source file
outside of any sub or block, it is best called a file scoped lexical. it
is visible from the point (or just after :) of the declaration to the
end of the file. you can even declare another my variable of the same
name and it will now be scoped to the end of the file (but it will
generate a warning so don't do it). these types of variable are also
called file globals as they are usually global to the entire file (even
though the declararation is lexical.
what most perl uses of global mean are what is more properly called
package globals. this means they are in the symbol table and truly
global to the entire program (as long as you know where to find it in
the symbol table, you can mung it at a distance).
so we have the lexically declared file scoped 'globals' and
program/package 'globals'. please note the difference now and when you
discuss these in the future. i won't even bring up 'our' which just adds
to the confusion by being a lexical declaration of a package global!
uri
--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
.
- Follow-Ups:
- References:
- my variable is recognized in following sub
- From: david
- Re: my variable is recognized in following sub
- From: Scott Bryce
- Re: my variable is recognized in following sub
- From: xhoster
- my variable is recognized in following sub
- Prev by Date: Re: Efficient Code
- Next by Date: Re: Efficient Code
- Previous by thread: Re: my variable is recognized in following sub
- Next by thread: Re: my variable is recognized in following sub
- Index(es):
Relevant Pages
|
Loading