Lou Hernsen wrote:
----- Original Message ----- From: "Bob Showalter" <[EMAIL PROTECTED]>
To: "Lou Hernsen" <[EMAIL PROTECTED]>
Cc: <beginners-cgi@perl.org>
Sent: Sunday, November 27, 2005 12:36 PM
Subject: Re: our..



Lou Hernsen wrote:

ok after reading about "our"

fact:
I use all global vars in the main program.
conclusion
I need to list all the vars in the module as our

in main
my $foo
in mod
our $foo

this will allow the vars to be used by both programs?

No.

A variable declared with "my" is only accessible within the enclosing file, block, or eval.


File is the entire program.. like a global var?

File is a single source code file. I assumed in your example above, that the "main program" and "module" were in two separate files.

Block is the "if" or "while" or other {} framed code?
what is an eval? if (my $var=0;$var>10;$var++)
is that when you mean? an evaluation?

No, I mean the eval() function within Perl.



"our" is a declaration that allows you to use a global (symbol-table) variable name without a package qualifier when "use strict" is in effect.



from what you say "our" is used in the main program
so I don't have to declare them again in the mod?

No. "our" is a lexical declaration. From the point at which it appears, going forward to the end of either a) the innermost enclosing block (or eval), or b) the end of the source code file, you may use the variables named in "our" without a package qualifier.

Example:

   use strict;

   $foo = 10;               <-- generates error
   $main::foo = 10;         <-- fully qualified; this is OK

   our $foo;

   print $foo;              <-- this is allowed now
   print $main::foo;        <-- and is equivalent to this

"our" and "my" operate on two completely different kinds of variables; they have no interaction with each other.

So if I run the mod as one big ad-in program to main
and not calling subs in the mod, I don't have to pass vars in the ()'s?
stats;
and not
stats::sub($var1, $var2, etc....);

The module can access global variables. If the variables are in the same package, you can reference them unqualified as long as you declare them with "our" (in whichever file(s) you are referencing them). If they are in different packages, you need to qualify them with package statements.


this mode only does some calulations and print to the HTML code...


thanks
Lou








--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to