| Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 | 1. Stem tail substitution #12554 Posted by: PeterJ 2008-12-06 16:16:18 | the following code sequence returns an error:
CB.peter.0=5 var='Peter' say cb.var
CB.Peter has no value.
It seems Reginald stem tails become case sensitive if created/accessed via tail substition.
Whereas Cb.Fred=5 say cb.fred
is case insensitive. Is this behaviour intended? I couldn't check how Z/OS Rexx behaves.
Peter | 2. #12555 Posted by: Jeff Glatt 2008-12-06 19:27:12 Last edited by: Jeff Glatt 2009-03-04 13:43:13 (Total edited 2 times) | Yep, tail names are case-sensitive. There's a discussion of this in "The REXX Language -> Variable Arrays". | 3. #12557 Posted by: PeterJ 2008-12-06 19:42:19 | ok, understand! I just wonder why then
Cb.Fred=5 say cb.fred
works as if there was no difference between Cb.Fred and Cb.fred
No problem for me, I just like to understand ... | 4. #12558 Posted by: Doug Arndt 2008-12-06 22:29:21 Last edited by: Jeff Glatt 2009-03-04 13:49:29 (Total edited 3 times) | I believe all undefined variables are internally defined as their upper case name, at least used to be, the NOVALUE catch confuses that.
Try this...
Cb.Fred=5 say cb.fred say cb.FRED
var = 'FRED' say cb.var
You'll note they all work. But if you put a "say Fred" in there, that fails due to NOVALUE. (With legacy Reginald, it used to give "FRED". Everything used to default to the uppercase value, but now you'll crash).Doug | 5. #12561 Posted by: Jeff Glatt 2008-12-07 06:26:57 Last edited by: Jeff Glatt 2009-03-04 13:51:01 (Total edited 8 times) | What you do is take advantage of substitution itself to use a variable name that is not all upper case:
i = 'Peter'
cb.i = 1
SAY cb.i I just wonder why then
Cb.Fred=5 SAY cb.fred
works as if there was no difference between Cb.Fred and Cb.fred This works because, when REXX loads a script, it automatically upper-cases everything except what is inbetween quotes (ie, a literal string). So your script gets loaded as:
CB.FRED = 5 SAY CB.FRED
Notice that everything not in quotes is converted to upper-case. So, the mixed case in your original script is irrelevant. The variables names match up once the script is loaded.
So tail names that you specify in the script always take on upper-case. You therefore normally don't run into problems until you do that tail assignment above, which is what Peter did:
cb.peter = 5
VAR = 'Peter'
SAY cb.var The moral of the story:
When you intend to use a variable as a tail name, make sure the variable's value is numeric (ie, defeats substitution), or is all upper-case. (Or, the variable was never assigned a value, in which case its value is the variable name upper-cased).cb.peter = 5
VAR = 'PETER'
SAY cb.var | Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 |
|
|