Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? set /r

Jul
576
10
so i stated using set/r and spent about an hour moving all my env var defs from .btm to .env (my own extension for env var files i read with the set /r command)

Oh wow. Vars that are defined as other aren’t fleshed out automatically.
What i mean is if i put:

whatever_test1=whatever_test1
whatever_test2=%whatever_test1%

Then the correct values will come out with an echo command

But if i read them in perl (and probably in python), whatever_test2 is %whatever_test_1%.
That is, it’s the variable it’s aliased to, and the value is not fleshed out, nor can it be.

Besides researching the aliased environment variable name and using the correct one, how can I avoid this?

Is there a variant of set /r that evaluates aliases, or does this defeat the timesaving? (And if so, maybe that’s what we want to do)


I could always update every perl script but ummmm... ugh. That’s a job for Codex.
 
i might just have to nuke over an hour of work in moving my huge environment variable definition payload to this format to save speed only to find out the variable values aren’t REALLY assigned, which i guess is the speedup, but, whaever time it may have cumulatively saved over my life wasn’t actually gonna payback my investment, oops. Now it defiitely won’t. My problem, but dang. Didn’t expect to have to read the docs that closely
 
SET /R will not expand variables, and there is no variant that will make it do that. SET /R saves the variable and value exactly as you entered it (which (1) allows it to be much faster, and (2) allows the value to be expanded when you execute it instead of during the SET, without requiring back quotes).
 
. . . . Vars that are defined as other aren’t fleshed out automatically.
What i mean is if i put:

whatever_test1=whatever_test1
whatever_test2=%whatever_test1%

Then the correct values will come out with an echo command [in TCC]

But if i read them in perl (and probably in python), whatever_test2 is %whatever_test_1%.
That is, it’s the variable it’s aliased to, and the value is not fleshed out, nor can it be.

"Nor can it be"?? In perl?

Expanding the value of nested variables in perl is not automatic, but there are several ways to do it. You can read about this by running "perldoc perlfaq7" and searching for the question "How can I use a variable as a variable name?"

You may have decided on another method to resolve the problem, but if you have not, here is one way to do it in perl:
Perl:
use strict;
use v5.12;
my (@keys, %hash);

while ( <DATA> ) {
  if ( m/(\w+)=(\w+)/ ) {
    say "Matched on word: $1 = $2";
    push (@keys, $1);
    $hash{$1} = $2;
  }
  elsif ( m/(\w+)=%(\w+)%?/ ) {
    say "Matched on  var: $1 = var $2";
    push (@keys, $1);
    $hash{$1} = exists $hash{$2} : $hash{$2} : "[undefined]";
  }
}

foreach (@keys) {
  say "For the key '$_', value is '$hash{$_}'";
}

__DATA__
whatever_test1=blurk
whatever_test2=%whatever_test1%
whatever_test3=%no_such_variable%

:Edit - fixed perl script to check for undefined variables.

I hope you or someone finds this helpful.
 
Last edited:
Back
Top