Understanding a Mumps statement
What is the meaning of this st开发者_运维百科atement: S A=$P(P,,2) I S
?
This may not be valid syntax based on the MUMPS implementation. For example, Intersystem Cache will generate a syntax error, since the second parameter passed to the piece function is blank.
The $P
or $PIECE(str, delim, num)
, function will return the num-th segment of str when delimited by delim. So, p("a^b^c","^",2)
returns "b". When delim is the empty string, $P
will return the empty string. However, there can be a difference between passing nothing and an empty string.
S A=$P(P,,2)
says to set the variable A to the value returned by the piece function.
Finally, I S
, says that if the value of variable S evaluates to true, continue executing the rest of this line. The I
or IF
command also has the side effect of setting the $T
variable to 1 if the expression is true, or 0, if the expression is false. This is important if your line of code is followed by an else statement, which uses $T
to determine whether the previous if statement returned false.
It means
Set A = $PIECE(P,,2)
$PIECE(string,delimiter,from)
returns the substring which is the nth piece of string, where the integer n is specified by the from parameter, and pieces are separated by a delimiter. The delimiter is not returned.
The links to the documentation is here: http://docs.intersystems.com/cache20102/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fpiece
精彩评论