Setting array variable ignores leading spaces (and @execarray doesn't)

May 20, 2008
10,671
83
Syracuse, NY, USA
Setting array variable ignores leading spaces. And @execarray[] doesn't. This is a problem. I can't fill an array with @execarray[] copy it to another array expecting the copy to be the same.
Code:
v:\> setarray a[1]

v:\> set a[0]=  xx

v:\> echo **%a[0]**
**xx**

v:\> echo %@execarray[a,echo   xx]
0

v:\> echo **%a[0]**
**  xx**
 
May 20, 2008
10,671
83
Syracuse, NY, USA
I haven't tried it, but try enclosing your argument in back quotes, i.e., set a[0]= ` xx`
It doesn't work. And even if it did, copying an array would be impossible. In
Code:
set b[%i]=`%a[%i]`
neither %a nor %i on the right hand side would be expanded.

My situation: array a is filled by @EXECARRAY and NETSTAT.EXE. It has leading spaces.
 

samintz

Scott Mintz
May 20, 2008
1,433
13
Solon, OH, USA
I know this doesn't directly address your issue, but you could always assume there are leading spaces and remove them prior to using them - e.g. @TRIM[%a[%i]]
 
May 20, 2008
10,671
83
Syracuse, NY, USA
I know this doesn't directly address your issue, but you could always assume there are leading spaces and remove them prior to using them - e.g. @TRIM[%a[%i]]
There are many ways to kludge around the problem. Most efficient might be to get rid of them in the first place ...

Code:
@execarray[a,netstat -ano | get_rid_of_leading_spaces]

TPIPE could do that but would be slow compared to, say, SED.