[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

external variables

Posted on 1999-11-23
9
Medium Priority
?
765 Views
Last Modified: 2012-08-13
I've got a perl script that generates reports based on a series of variables.  I'd like to move these variable assignments out into a config file, and suck them in after I determine which set of configs to use.

I'm currently using require to do this, but the results are less than what I expected.  If I take my variable assignments and move them to the config file, and require in the config file, I get "some" of the values.  If I leave them in the script, it works as I expect.

Is there some other way or some better way to do this?

Eric
0
Comment
Question by:helver
9 Comments
 
LVL 4

Expert Comment

by:adam923
ID: 2229393
Are you using my, local, or package anywhere in the config file?
0
 
LVL 2

Author Comment

by:helver
ID: 2229397
Nope...  no mys, locals, or packages at all.
0
 
LVL 4

Expert Comment

by:adam923
ID: 2229405
Can you post code snippets of variables that work and those that don't... both the config file and the main file?  Maybe you should just write the config file as a few lines of key=value and then parse into a hash in the main program?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:helver
ID: 2229515
I got it to work... I'll explain in more detail what I saw and why I was so confused.  I'd still like a cleaner way to do this, though, so I'll leave the question open for a bit...

In my program I had the following:

my @a, @b, @c
my $aa, $ab, $cd, @d;
my @e, @f;
my %g, %h;
my $ii, $jj, @k;

require "config_file.conf" if ( -e "config_file.conf");

# Print each predeclared variable.


-------

# in config_file.conf

@a = ("ab");

# etc, etc, etc


What I saw was most variables received the values they were given in "config_file.conf".  The ones that didn't were @a, $aa, @e, %g, and $ii.  These variables just happened to have been the first ones in each my declaration.

I combined the my statements into a single one, then only @a was undefined.  I stuck a dummy variable in at the beginning, and then all the variables were defined - all expect one that I had in a different my statement.

In the end, I removed all the my's from the global variables in my script, and it all seems to work as I would expect.  Can anyone tell me why having my's in the main program would cause such an effect?  That only SOME of the variables got their proper values from the required in file?

Eric
0
 
LVL 4

Accepted Solution

by:
adam923 earned 800 total points
ID: 2229543
I guess my comment before should have been "do you use my or local vars anywhere?" but that's not what I asked... oh well, the my keyword binds tightly... which is to say that you meant
my(@a, @b, ...); but you really said my(@a),@b,...;  Since the scope of my variables ends at the end of a file, those that actually got the my declaration were limited to the config file.
As I alluded to earlier i think just writing your configuration variables in a plain text file and then parsing this file in the program is the way to go.  Let me know and I'll write you an example of this
0
 
LVL 2

Author Comment

by:helver
ID: 2229876
cool man... I think I got it from here....
0
 
LVL 85

Expert Comment

by:ozo
ID: 2230273
0
 
LVL 16

Expert Comment

by:maneshr
ID: 6917169
All,

This question seems to be abandoned. As part of the ongoing cleanup effort, I will leave a note in
the Community Support topic area which will recommend to the Moderators that they close this question.

My recommendation will be to award the points to adam923.

PLEASE DO NOT AWARD THE POINTS TO ME.

Experts ===>: please leave your thoughts here. <====

maneshr
(NOT a moderator at EE)
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6940168
Per recommendation, force-accepted by
Netminder
CS Moderator
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question