Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -1,33 +1,78 @@
|
|||
/*REXX program merges two associative arrays (requiring an external list of indices). */
|
||||
$.= /*define default value(s) for arrays. */
|
||||
@.wAAn= 21; @.wKey= 7; @.wVal= 7 /*max widths of: AAname, keys, values.*/
|
||||
call defAA 'base', "name Rocket Skates", 'price 12.75', "color yellow"
|
||||
call defAA 'update', "price 15.25", "color red", 'year 1974'
|
||||
call show 'base'
|
||||
call show 'update'
|
||||
call show 'new'
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
defAA: procedure expose $. @.; parse arg AAn; new= 'new' /*get AA name; set NEW.*/
|
||||
do j=2 to arg(); parse value arg(j) with key val /*obtain key and value.*/
|
||||
$.AAn.key= val /*assign a value to a key for AAn. */
|
||||
if wordpos(key, $.AAN.?keys)==0 then $.AAn.?keys= $.AAn.?keys key
|
||||
/* [↑] add to key list if not in list.*/
|
||||
$.new.key= val /*assign a value to a key for "new".*/
|
||||
if wordpos(key, $.new.?keys)==0 then $.new.?keys= $.new.?keys key
|
||||
/* [↑] add to key list if not in list.*/
|
||||
@.wKey= max(@.wKey, length(key) ) /*find max width of a name of a key. */
|
||||
@.wVal= max(@.wVal, length(val) ) /* " " " " " " " " value.*/
|
||||
@.wAA = max(@.wAAn, length(AAn) ) /* " " " " " " " array.*/
|
||||
end /*j*/
|
||||
return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: procedure expose $. @.; parse arg AAn; say; _= '═' /*set title char.*/
|
||||
do j=1 for words($.AAn.?keys) /*process keys. */
|
||||
if j==1 then say center('associate array', @.wAAn, _) ,
|
||||
center("key" , @.wKey, _) ,
|
||||
center('value' , @.wVal + 2, _)
|
||||
key= word($.AAn.?keys, j) /*get the name of a key.*/
|
||||
say center(AAn, @.wAAn) right(key, @.wKey) $.AAn.key /*show some information.*/
|
||||
end /*j*/
|
||||
return
|
||||
-- 8 Aug 2025
|
||||
include Settings
|
||||
|
||||
say 'ASSOCIATIVE ARRAY: MERGE'
|
||||
say version
|
||||
say
|
||||
call CreateBase
|
||||
call ShowBase 'Original'
|
||||
call CreateUpdate
|
||||
call ShowUpdate
|
||||
call MergeBaseUpdate
|
||||
call ShowBase 'Merged'
|
||||
exit
|
||||
|
||||
CreateBase:
|
||||
base=''; base.=''
|
||||
call ProcBase 'name','Rocket Skates'
|
||||
call ProcBase 'price',12.75
|
||||
call ProcBase 'color','Yellow'
|
||||
return
|
||||
|
||||
ShowBase:
|
||||
parse arg xx
|
||||
sep=Copies('-',20)
|
||||
say 'Base array' xx
|
||||
say sep
|
||||
say 'Key value'
|
||||
say sep
|
||||
do i = 1 to Words(base)
|
||||
key=Word(base,i)
|
||||
say Left(key,6) base.key
|
||||
end
|
||||
say sep
|
||||
say
|
||||
return
|
||||
|
||||
CreateUpdate:
|
||||
upda=''; upda.=''
|
||||
call ProcUpdate 'price',15.25
|
||||
call ProcUpdate 'color','Red'
|
||||
call ProcUpdate 'year',1974
|
||||
return
|
||||
|
||||
ShowUpdate:
|
||||
say 'Update array'
|
||||
say sep
|
||||
say 'Key value'
|
||||
say sep
|
||||
do i = 1 to Words(upda)
|
||||
key=Word(upda,i)
|
||||
say Left(key,6) upda.key
|
||||
end
|
||||
say sep
|
||||
say
|
||||
return
|
||||
|
||||
MergeBaseUpdate:
|
||||
do w = 1 to Words(upda)
|
||||
key=Word(upda,w); val=upda.key
|
||||
call ProcBase key,val
|
||||
end
|
||||
return
|
||||
|
||||
ProcBase:
|
||||
parse arg k,v
|
||||
if WordPos(k,base) = 0 then
|
||||
base=base k
|
||||
base.k=v
|
||||
return
|
||||
|
||||
ProcUpdate:
|
||||
parse arg k,v
|
||||
if WordPos(k,upda) = 0 then
|
||||
upda=upda k
|
||||
upda.k=v
|
||||
return
|
||||
|
||||
include Abend
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue