Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my/our/var/local...use strict?

Status
Not open for further replies.

eve25

Programmer
Feb 9, 2004
32
US
Hi guys,

Here is my problem : I need a global variable and to use strict at the same time (the program is quite big and I need to debug easily..)
If I get everything:
local: I can get global variables but not use strict
my: declaration in one block /can use strict
our: declaration in one block and 'children blocks'/can use strict (as local but use strict (?))
var: apparently that s what I need cause I want to be able to reach my variables from others packages (a lot of my subroutines are in other packages ().. but maybe that's bad...?)but writing 'use vars' is OK and then if I try to declare 'var $smth;', it doesn't recognize the command...
I have seen this 'var::i' package but I am not sure that's what I need...

Could someone help me?
Thanks a lot!
 
So you want to have a global debug variable that's viewable in all packages?

The easiest way to do it is probably just specify the full package name:

$main::DEBUG = 1; # turn debugging on.

Hope this helps,

--jim
 
I would recommend the use of a debugging module. I am a big fan of Log4Perl.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
If the file is really huge maybe you should split it up into several modules with each clear defined functionality?
 
Here's a trivial example:


use strict "vars";
$soda = "Coke";

Since we haven't told Perl what $soda is, it will complain with the following error:


details as follows

Global symbol "$soda" requires explicit package name at simple line 3.
Execution of simple aborted due to compilation errors.

We can solve this problem by using a fully qualified variable name, declaring the variable using the vars module, or localizing it with my, like so:


$main::soda = "Coke"; ## Fully qualified
use vars qw ($soda); ## Declare using vars module
my $soda; ## Localize
 
Thanks everyone for your answers!
I think arcnon one is what I need..
Have a great day!
Eve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top