Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Array tail

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Array tail
#1279
Posted by: guidance 2002-11-05 11:28:40
Reginald doesn't support direct string as array tail (subscript)?

I write:
const.'crlf'='old'
SAY const.'crlf'
The output (OOOh, I can't copy the contents in output console window of RexxEd to paste here either!):

CONST.CRLF

If I write:
const.crlf='old'
SAY const.crlf
The output is correct ('old').

I understand the later one is equivalent with:
crlf='CRLF'
const.crlf='old'
SAY const.crlf
but can't understand the behaviour of the first example (no any error reported).
Message2. Re: Array tail
#1282
Posted by: 2002-11-05 15:19:27
You can't use quotes in tail names. So REXX is interpreting

const.'crlf'

...as the value of the stem variable named const. (which is here the default of CONST.) joined with the literal string 'crlf'. It doesn't see the = sign as a variable assignment because there isn't *only* a variable name on the left side of the = sign. You've got a variable joined with a literal string. That's an operation, not a variable name. So how does REXX regard the = sign? It regards it as a comparison test. It is checking the value of a combined string of "CONST.crlf" to the literal string 'old'. It's as if you typed:

'CONST.crlf' = 'old'

And the value of this expression is FALSE (ie, 0). So the result of this entire line is if you simply typed:

0

Now what does REXX do with a line that is simply the above? REXX doesn't know what else to do with this. And what does REXX do with a line it doesn't know what to do with? You guessed it. It sends it off to the shell. Run your script again (but not from RexxEd. RexxEd's console window isn't a real console, and so the shell doesn't display error messages to it). See that error message:

'0' is not recognized as an internal or external command.

Ok, so since your first line is not a variable assignment, that means you really haven't assigned any value to a variable named CONST.CRLF. And that's why when you SAY it, you get its default value.

In conclusion, if you want a variable assignment, then make sure you put only a variable name on the left side of the parentheses. And variable names do not contain quote characters.

By the way, are you trying to defeat "tail name substitution" just so you don't accidentally set the variable named CRLF to some value other than its own name? I think that a better alternative is to use a dollar sign as the first character of your tail name. And then never use a simple variable name that begins with a dollar sign. Here's an example:

const.$crlf = 'whatever'

Now, never use the variable $crlf in your script. You'll never have to worry about $crlf being substituted with anything else
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥289.00 ·
 
 
¥1,080.00 ·
 
 
¥1,380.00 ·
 
 
¥638.00 ·
 
 
¥1,290.00 ·
 
 
¥1,420.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0