Is there a way to make associative arrays in REXX?

I have some Perl code (for performance analysis), first developed under Linux, which now needs to be ported to the mainframe. REXX appears to be the language of choice scripts on this platform, but this Perl script relies heavily on associative arrays (mostly arrays where the index is a string).

Is there a way that in REXX? How would I encode something like:

$arr{"Pax"} = "Diablo";
$arr{"Bob"} = "Dylan";
print $arr{"Pax"} . "\n";
if (defined $arr{"no"}) {
        print "Yes\n";
} else {
        print "No\n";
}
+5
source share
2 answers

You can use stack variables, not as 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 aforementioned Rexx will print

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

, a.b.c , , . , , .

IBM

Perl ZOS IBM Ported Tools z/OS

+12

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

, 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 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 */, REXX Z/OS.

+10

All Articles