Karl-Heinz Kuth wrote:
> Hi,
>
> first time I answer myself ;-). Here's my solution:
>
> I cut off the cmd-file for the example and set the env var in the
> script. After all, the value of the env var "%%FOO_TOKEN%_DIR%" will be
> created without using the env vars "FOO_TOKEN" or "BAR_DIR" directly.
>
> The idea was to use the system command set and redirect the output of
> that statement. The analyse of the output is quite simple.
>
> Thanks to Bill, who said, that the command "set %FOO_TOKEN%_DIR" works
> properbly in the shell.
>
> Here is the script:
>
> --- beginn ---
>
> use strict;
> use warnings;
>
> # init
> $ENV{ FOO_TOKEN } = "BAR";
> $ENV{ BAR_DIR } = "c:\\bar";
> my $foo_token_dir = "";
> my @foo_indirect = "";
> my $foo_token_value = "";
> # end of init
>
> # set the var as you like
> $foo_token_dir = "%%FOO_TOKEN%_DIR%";
> #$foo_token_dir = "%BAR_DIR%";
>
> # main
>
> $foo_token_dir =~ s/^%//;
> $foo_token_dir =~ s/%$//;
>
> # in real life, don't forget to check the index and the output!
> @foo_indirect = `set $foo_token_dir 2>&1`;
> $foo_token_value = $foo_indirect[ 0 ];
> $foo_token_value =~ s/^\s+//;
> $foo_token_value =~ s/\s+$//;
> $foo_token_value =~ s/([^=]+)=(.*)/$2/ ;
>
> print "foo_token_dir: " . $foo_token_dir . "\n";
> print "foo_token_value: " . $foo_token_value . "\n";
>
> # end of script
My version:
use strict;
use warnings;
$ENV{FOO_TOKEN} = 'BAR';
$ENV{BAR_DIR} = 'C:\\bar';
print "ENV{FOO_TOKEN} = '$ENV{FOO_TOKEN}'\n";
print "ENV{BAR_DIR} = '$ENV{BAR_DIR}'\n";
my $foo_token_dir = '%%FOO_TOKEN%_DIR%';
$foo_token_dir =~ s/^%//; # '%FOO_TOKEN%_DIR%';
$foo_token_dir =~ s/%$//; # '%FOO_TOKEN%_DIR';
print "foo_token_dir: $foo_token_dir\n";
# my @foo_indirect = `set $foo_token_dir 2>&1`;
# the above code is just as easily done without shelling:
$foo_token_dir =~ s/%([^%]+)%/$ENV{$1}/;
# and get the value
my $foo_token_value = $ENV{$foo_token_dir};
print "foo_token_dir: $foo_token_dir\n";
print "foo_token_value: $foo_token_value\n";
# my $foo_token_value = $foo_indirect[0];
# my $foo_token_value = $foo_token_dir;
# $foo_token_value =~ s/^\s+//;
# $foo_token_value =~ s/\s+$//;
# $foo_token_value =~ s/([^=]+)=(.*)/$2/;
# print "foo_token_value: $foo_token_value\n";
__END__
The problem with this is you haven't accomplished anything. Running
the script does not permanently set the env vrbls - once the script
exits, the env is back to where it was before.
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs