Welcome!

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

SignUp Now!

Is this of any value?

May
12,845
164
I have a skeleton for something like:

Code:
WSCAN [/D "delims"] (varname | *) [varname | *] ... /S string
which **uses @WORD** to set envvars to the various words in a string, with "*" skipping a word. It is of value? ... comments/suggestions? I'm not going to make it too complicated. Here are some examples.

(a somewhat practical one) the file ipv4.txt is a collection of lines like:

Code:
1.0.0.0   1.0.0.255   01000000 010000FF   apnic   256
I could, for example,

Code:
v:\> wscan IPSTART IPEND * * INETREGISTRY /s %@line[u:\inet\ipv4.txt,9170]
Then I'd have

Code:
v:\> set
INETREGISTRY=arin
IPEND=207.45.71.255
IPSTART=206.253.144.0
These two show that the end of the string is ignored and that unfilled variables are set to an empty string. I should probably make them not defined at all (conventional and easier to test with "DEFINED var").

Code:
v:\> wscan /D "13579" v1 v2 v3 /s 0123456789

v:\> set
v1=0
v2=2
v3=4

v:\> wscan /D "13579" v1 v2 v3 v4 v5 v6 /s 0123456789

v:\> set
v1=0
v2=2
v3=4
v4=6
v5=8
v6=
 
I have a skeleton for something like:

Code:
WSCAN [/D "delims"] (varname | *) [varname | *] ... /S string

Sounds good. Some suggestions, though:

1. Use something other than * for skipped values, perhaps -.

Using a dummy variable name could work, too, as in

Code:
   WSCAN  V1 X V2 X V3 /S "FOO BAR BAZ ZORCH QUUX"
would get V1=FOO, V2=BAZ, and V3=QUUX (and X=ZORCH), but we're not interested in X.

Also,
Code:
   WSCAN   FOO FOO FOO FOO /S "This is the forest primeval"
would make FOO=primeval.

2. Allow the variable names to be read from a file with
Code:
   WSCAN  /R @varname.txt /s "line to be parsed"

3. Allow filling of array variables with
Code:
  WSCAN  ARRAYVAR[] /S "VAL1 VAL2 VAL3"
would set ARRAYVAR[0]=VAL1, ARRAYVAR[1]=VAL2, ARRAYVAR[2]=VAL3.

4. Allow a "field" scan, rather than a "word" scan, perhaps with another verb, such as FSCAN that works similarly.
Code:
 FSCAN /D ","  X Y Z  /S "A,,B"
would set X=A and Z=B, but Y would be undefined.
 
On Wed, 09 Jun 2010 08:44:48 -0400, dcantor <> wrote:

|1. Use something other than * for skipped values, perhaps -.

Or maybe '!'.

|2. Allow the variable names to be read from a file

Possible. But it's hard to imagine many would do that.

|3. Allow filling of array variables with

That could be done. What about ARRAYVAR[1][] vs. ARRAYVAR[][1] (filling row vs.
column of a 2 (3,4) dimensional array?

|4. Allow a "field" scan, rather than a "word" scan, perhaps with another verb, such as FSCAN that works similarly.

Trivial, since I'm using @WORD to do the work.

I did some testing last night. WSCAN is exactly the same speed as equivalent
batch code. And the savings in what needs to be typed is modest (would be
greater with varnames from file or (maybe) array names). I'm not convinced of
the value.

Your mentioning arrays brings up a question. Is it possible to reference an
array element having the array name end the element index in variables? The
obvious (?) doesn't work.

setarray n[5]

set n[0] = 10

set name=n

set index=0

echo %[%name[%index]]
ECHO is OFF

echo %name[%index]
n[0]

set ename=%name[%index]
echo %[%ename]
ECHO is OFF
--
- Vince
 

Similar threads

Back
Top