For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > November 2005 > Re: our..... Lou's code









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: our..... Lou's code
Bob Showalter

2005-11-28, 6:55 pm

Lou Hernsen wrote:
> ----- Original Message -----
> From: "Bob Showalter" <bob_showalter@taylorwhite.com>
> To: "Lou Hernsen" <lhernsen1015@wowway.com>
> Cc: <beginners-cgi@perl.org>
> Sent: Sunday, November 27, 2005 12:36 PM
> Subject: Re: our..
>
>
>
>
>
> 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.

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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com