[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Scoping question



>>   # if we pass to here, the XML file is fine.  now parse to create a
>>   # list of subjects in the file.
>>   $nSubjects = 0;
>>
>>   $p3 = new XML::Parser(Handlers => {Start => \&hStartCnt});
<SNIP>
>Not a global variable.  A lexical variable is not global.  Access to it is
>limited to the lexical scope.  In this case, the lexical scope is the file
>(or if all of this code is in a block, then the lexical scope if the whole
>block).

Just to clarify terminology, MPPE (as you know ;-) states that:

"Any variables created (or used) within a Perl program, which are not
explicitly made private, are global; that is, they (and their current 
values)
are available to your entire program, including subroutines. "

As I read the subsequent material, a variable is made private using the 
"my" keyword, so in my script, $nSubjects should be "global" in the sense 
referred to in the quote.  I can only interpret "global" in the sense of 
lexical scoping, where the current code block is the whole file, and the 
whole file knows the value of $nSubjects.  Correct?

>
>But that is neither here nor there.  You are setting $nSubjects _after_
>hStartCnt is called.  It will always be 0 because "$nSubjects = 0" is the
>last line of code to execute before the "if($nSubject == 0)" line.

Duh.  Still on the Perl learning curve, I got so worried about scope, 
variable declarations, etc. I forgot the simple, no-brainer issues.  
Sorry for the stupid question.

Rick

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org