Dear Bill and the others,
You can't set $foo_token (or $foo_token_dir ) to $ENV{ FOO_TOKEN}.
The value ot the variable has to be "%%FOO_TOKEN%_DIR%".
What you set in the BAT file was :
FOO_TOKEN=BAR
BAR_DIR=c:\bar
So the only ENV vrbls available are FOO_TOKEN and BAR.
The %'s are used to indicate to the shell to interpolate. eg:
%FOO_TOKEN% is interpolated to the value of 'FOO_TOKEN' env vrbl
which is 'BAR' so 'CALL SET %FOO_TOKEN%_DIR=c:\bar' sets 'BAR_DIR'
to 'C:\bar'
That's true, and the indirection is what I want! If I don't want
to use the inderection, I wouldn't ask.
It's a little bit complecated, but I think I have to explain it.
I set CALL SET %FOO_TOKEN%_DIR=c:bar in a cmd-file to declare
directories I will use in my script. All directories are decleared in
that way. So if there are changing of the structure of your directory, you just
change it here.
Fine so you just set BAR_DIR to c:\bar - no problem so far
Correct, but that's not what I want.
You may ask, why don't you use a fix prefix like SET FOO_DIR=c:bar?
That's because, I want to be flexible. If someone has already used "FOO_DIR"
in his environment, you have a problem. So I want to be able to change
the prefix in an easy way.
No problem with the indirection.
Correct, because it's no problem, I want to use it that way.
In the script, I run the cmd-file, so that I have all the directories in an
environment variable. In real life, it's not that easy to get them in the
perl hash "%ENV". But this should not be a part of the discussion.
Sure it is - whatever is in the output of set will also be in %ENV if
you immediately run a perl script.
You should execute the cmd-file before, so that the environment
variables are set and perl can use them. I made this workaround to solve
this problem, because it's the easiest way. In my real perl script I do
it in the script, so that perl can use the env vars. A simple system
call does not solve this. I can tell how I do it, but this is not part
of the problem.
>>So I read in the ini-file and it has the value "%%FOO_TOKEN%_DIR%".
Now I want the other way back to get the name of the directory, in that
case "c:bar".
Who's reading the ini file - perl or a bat script ? If Perl is reading
it, it's not gonna work unless the script shells off the commands you
want to do next. It the bat script does it, it would firsst have to break
up the two levels of indirection and do them one at a time as you did:
Sorry for that, perl is reading the ini-file via a perl module into a
hash and I create an env var for every entry (for some good reasons).
Later I can refer to the env var instead of the ini-file hash. This env
variables will be placed in a perl variable later in the script, like
the line
my $foo_token_dir = "%%FOO_TOKEN%_DIR%";
In my original script I use an env var, that I created. The env var,
that I use, has exact this value.
I know, that the shell interpolates the inderection and perl does not.
But perl (so I) should do it! That's my problem.
I think we do - but I don't think you do. ;) You need to 'splain
more about how you get from ini file to scrip/bat file.
So the perl script does the following:
1) reads the cmd-file
2) set the env vars
3) reads the ini-fle
4) set env vars for every entry
5) Interpolate the indirection
Yes, you are right. I understand. Even the problem is hard to describe.
Thanks
Karl-Heinz
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs