Re: my variable is recognized in following sub



"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 ---------
.



Relevant Pages

  • RE: scope of public variables
    ... "Jim Thomlinson" wrote: ... If your globals are declared anywhere other than a standard code module ... is where did you declare your variable. ... Sub optCkforDupes_Click ...
    (microsoft.public.excel.programming)
  • Re: Beautiful Python
    ... >> This seems to be the de facto standard in the Perl community but in ... This does not resemble Java imports. ... Pascal's restriction of not being able to declare globals, ... Ie. the ability to declare them at a 'nice' place is just syntactic ...
    (comp.lang.python)
  • Re: my variable is recognized in following sub
    ... x> Aren't global variables the same thing as package variables? ... at least not in Perl vernacular as I understand it. ... is visible from the point of the declaration to the ... called file globals as they are usually global to the entire file (even ...
    (comp.lang.perl.misc)
  • Re: Help with this code, please
    ... lineno +:= 1 ... args is a local variable within main, but you're trying to use it ... The order doesn't matter, globals may be declared ... prefer to declare all variables. ...
    (comp.lang.icon)
  • Re: Help with this code, please
    ... The order doesn't matter, globals may be declared ... prefer to declare all variables. ... would over-write the built-in function pos(), ...
    (comp.lang.icon)

Loading