external variables

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
LVL 2
helverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

adam923Commented:
Are you using my, local, or package anywhere in the config file?
0
helverAuthor Commented:
Nope...  no mys, locals, or packages at all.
0
adam923Commented:
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

helverAuthor Commented:
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
adam923Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
helverAuthor Commented:
cool man... I think I got it from here....
0
ozoCommented:
0
maneshrCommented:
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
NetminderCommented:
Per recommendation, force-accepted by
Netminder
CS Moderator
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.