有没有办法在 REXX 中进行关联数组?

发布于 2024-09-30 11:08:58 字数 328 浏览 1 评论 0原文

我有一些 Perl 代码(用于性能分析)首先在 Linux 下开发,现在需要移植到大型机。显然 REXX 是该平台上选择的脚本语言,但这个 Perl 脚本严重依赖关联数组(基本上是索引为字符串的数组)。

REXX中有这样的方法吗?我将如何编写类似以下内容的代码:

$arr{"Pax"} = "Diablo";
$arr{"Bob"} = "Dylan";
print $arr{"Pax"} . "\n";
if (defined $arr{"no"}) {
        print "Yes\n";
} else {
        print "No\n";
}

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";
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌路黄昏 2024-10-07 11:08:58

你可以使用主干变量,不完全像数组,但非常相似

/* 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"

上面的Rexx将打印

ARRAY.PAX  IS DIABLO
ARRAY.BOB  IS DYLAN
ARRAY.SANDY  IS ARRAY.SANDY
ARRAY.SANDY IS EMPTY

它们也可以像abc一样复合
如果为空,stem 变量将返回其自身。
据我所知,没有办法迭代不使用连续数字作为索引的词干。

参考 Stem 变量的 IBM 手册

Perl 作为额外的免费功能提供给ZOS IBM z/OS 移植工具

You can use stem variables, not exactly like arrays but very similar

/* 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"

The above Rexx will print

ARRAY.PAX  IS DIABLO
ARRAY.BOB  IS DYLAN
ARRAY.SANDY  IS ARRAY.SANDY
ARRAY.SANDY IS EMPTY

They can also be compound like a.b.c
A stem variable if empty will return itself.
There is no way to iterate of a stem that does not use consecutive numbers as the index that I know of.

IBM Manual with reference to Stem variables

Perl is available as an extra free feature for ZOS IBM Ported Tools for z/OS

呆萌少年 2024-10-07 11:08:58

我只是想对 Deuian 给出的答案补充一点。
我同意,REXX 干变量
就是答案。

简单的 REXX 变量默认为其自己的名称。例如:

/* REXX */
SAY X

将打印“X”,直到为 X 分配其他值:

/* REXX */
X = 'A'
SAY X

将打印“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 */                                   

请注意,XA 词干名称未计算,但是,
它们后面出现的 XA 变量是。有些人认为这是一个
有点令人困惑——想一想就会发现
很有道理。

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

非常简单,但说明了这个想法。只要确保 INDEX (或您的任何名称)
选择)来保存索引名称永远不会作为关联值弹出!如果可能的话,请使用其他变量来保存索引。

最后一点。请注意,我的每个示例都以 /* REXX */ 开头,您可能会发现
这需要成为 Z/OS 下 REXX 程序的第一行。

I just want to add a bit more to the answer given by Deuian.
I agree, REXX stem variables
are the answer.

Simple REXX variables default to their own name. For example:

/* REXX */
SAY X

will print "X" until X is assigned some other value:

/* REXX */
X = 'A'
SAY X

will print "A".

No big surprise so far. Stem variables are a bit different. The
head of the stem is never evaluated, only the bit after the initial dot
is.

To illustrate:

/* 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 */                                   

Notice the X and the A stem names are not evaluated, however, the
X and A variables appearing after them are. Some people find this a
bit confusing - think about it for a while and it makes
great sense.

The Z/OS version of REXX does not provide a natural way to iterate over
a stem variable. The easiest way to do this is to build your own index.
For example:

/* 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

Pretty trivial but illustrates the idea. Just be sure that INDEX (or whatever name you
choose) to hold the indexing names never pops up as an associative value! If this is a possibility, use some other variable to hold the index.

Last point. Notice each of my examples begins with /* REXX */ you may find
that this needs to be the first line of your REXX programs under Z/OS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文