Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Scope of variables using strict

by btrott (Parson)
on Mar 22, 2001 at 23:45 UTC ( [id://66428]=note: print w/replies, xml ) Need Help??


in reply to Scope of variables using strict

You have several problems: one that I can see is with your code, another is with your implementation in general.

First, the problem with the code. You have, in control.cgi:

my $TestVar = "Test";
Then in required.cgi, you have:
my ($Test2Var) = $main::TestVar;
Your problem is that the var in control.cgi isn't in package main. my variables aren't in any package; their scope is lexical to the file or the surrouding block. Which means that your code in required.cgi has *no way* of accessing the $TestVar in control.cgi.

So right there, you have a problem: there's no way you can get that to work if you're using lexical variables in control.cgi and trying to access them in required.cgi.

And this comes back to your implementation: this is really not the best way to do this. If the code in required.cgi is to be used by a lot of scripts, you should package it up into either a library of exportable variables and functions or make some sort of OO interface (but *only if that makes sense*). From your message it sounds like what you may want most is the former, a library of exportable functions and variables. Take a look at perlmod and Exporter for that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://66428]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-25 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found