pax*_*blo 6 associative-array mainframe rexx zos
I have some Perl code (for performance analysis) first developed under Linux which now needs to be ported to the mainframe. Apparently REXX is the scripting language of choice on that platform but this Perl script relies heavily on associative arrays (basically arrays where the index is a string).
Is there a way that in REXX? How would I code up something like:
$arr{"Pax"} = "Diablo";
$arr{"Bob"} = "Dylan";
print $arr{"Pax"} . "\n";
if (defined $arr{"no"}) {
print "Yes\n";
} else {
print "No\n";
}
Run Code Online (Sandbox Code Playgroud)
Deu*_*ian 13
你可以使用干变量,不像数组那样但非常相似
/* REXX */
NAME = PAX
ARRAY.NAME = "DIABLO"
NAME = BOB
ARRAY.NAME = "DYLAN"
NAME = 'PAX'
SAY "ARRAY.PAX " IS ARRAY.NAME
NAME = 'BOB'
SAY "ARRAY.BOB " IS ARRAY.NAME
NAME = 'SANDY'
SAY "ARRAY.SANDY " IS ARRAY.NAME
IF ARRAY.NAME = "ARRAY.SANDY" THEN SAY "ARRAY.SANDY IS EMPTY"
Run Code Online (Sandbox Code Playgroud)
上面的Rexx将打印出来
ARRAY.PAX IS DIABLO
ARRAY.BOB IS DYLAN
ARRAY.SANDY IS ARRAY.SANDY
ARRAY.SANDY IS EMPTY
Run Code Online (Sandbox Code Playgroud)
如果为空,它们也可以像abc一样复合变量.没有办法迭代不使用连续数字的词干作为我所知道的索引.
Perl作为ZOS IBM Ported Tools for z/OS的额外免费功能提供
Nea*_*alB 11
我只想补充一点Deuian给出的答案.我同意,REXX干变量就是答案.
简单的REXX变量默认为自己的名称.例如:
/* REXX */
SAY X
Run Code Online (Sandbox Code Playgroud)
将打印"X",直到X分配一些其他值:
/* REXX */
X = 'A'
SAY X
Run Code Online (Sandbox Code Playgroud)
将打印"A".
到目前为止没什么大惊喜.干变量有点不同.从不评估杆的头部,只是初始点之后的位.
为了显示:
/* REXX */
X. = 'empty' /* all unassigned stem values take on this value */
A. = 'nil'
B = 'A' /* simple variable B is assigned value A */
X = 'A' /* simple variable X is assigned value A */
SAY X.A /* prints: empty */
X.A = 'hello' /* Stem X. associates value of A with 'hello' */
SAY X.A /* prints: hello */
SAY X.B /* prints: hello */
SAY X.X /* prints: hello */
Run Code Online (Sandbox Code Playgroud)
请注意,X并且A不会评估词干名称,但是,它们之后出现的
变量X和A变量是.有些人觉得这有点令人困惑 - 想一想,这很有道理.
REXX的Z/OS版本不提供迭代词干变量的自然方式.最简单的方法是构建自己的索引.例如:
/* REXX */
X. = ''
DO I = 1 TO 10
J = RANDOM(100, 500) /* Random # 100..500 */
X.INDEX = X.INDEX J /* concatinate J's with 1 space between */
X.J = 'was picked' /* Associate 'was picked' with whatever J evalauates to */
END
DO I = 1 TO WORDS(X.INDEX) /* Number of blank delimited 'words' */
J = WORD(X.INDEX, I) /* Extract 1 'word' at a time */
SAY J X.J /* Print 'word' and its associated value */
END
Run Code Online (Sandbox Code Playgroud)
非常琐碎,但说明了这个想法.只需确保INDEX(或您选择的任何名称)保持索引名称永远不会弹出为关联值!如果可能,请使用其他变量来保存索引.
最后一点.请注意我的每个示例都以/* REXX */您开始,您可能会发现这需要是Z/OS下REXX程序的第一行.