What is the meaning of this statement: S A=$P(P,,2) I S
?
2 Answers
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.

- 279
- 1
- 9

- 2,859
- 3
- 23
- 14
-
Can't add anything, except that in MUMPS spaces have important meaning, the general syntax is:
– ern0 Aug 19 '13 at 20:04..., so if there is no argument of a command, it is followed by two spaces: ... (Anyway, glad to see M users, or at least ex-users around here.)
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

- 5,559
- 8
- 37
- 50