This documentation space contains information about PATROL Agents when deployed in a TrueSight Operations Management environment. If you are a BMC Helix Operations Management user, see PATROL Agent 22.1 for BMC Helix Operations Management. Open link

Common PSL Coding Errors

This section describes common PSL coding errors that result in PSL compiler, interpreter, or run-time errors.

Character Strings Interpreted as Numbers

Errors can occur when numeric operations are applied to character strings where the first character is a digit or minus sign because PSL will evaluate these character strings as numbers.

Explanation: Before PSL performs an operation, it must determine whether the operands are numeric or character. To make this determination, PSL performs one of the following tests:

  • For relational operators, PSL tests that both operands consist entirely of digits, a period, and/or a minus sign. Otherwise, both operands are character type.
  • For arithmetic operators, PSL tests only that the first character of each operand is a digit or minus sign. Otherwise, both operands are character type that generates a run-time warning.

The run-time warnings perform the same check as the arithmetic operators.


These features remain for compatibility with previous releases of PATROL.

Arithmetic operators identify the character string "10th May" as the number 10 while relational operators correctly identify it as a character string. Its use as an arithmetic operand will not generate a run-time warning.

User Response: Be aware that character strings where the first character is a valid numeric representation can cause unexpected results in numeric operations that will not be detected by PSL diagnostics. Avoid using such strings.

Floating Point Numbers Interpreted as Character Strings

PSL interprets floating point numbers with a leading decimal point as character strings.

Explanation: Before performing a numeric operation, PSL evaluates both operands to verify that they are numbers. PSL tests only that the first character of each operand is a digit or minus sign. Upon detecting that the first character is a decimal point, PSL identifies the operator as a character string and returns a warning. For example, PSL identifies the operand 0.33 as a number and the operand .33 as a character string.

User Response: Begin each floating point number with a digit or a minus sign.

Character Strings Interpreted as Variable Names

PSL interprets character strings that are not enclosed in double quotation marks as variable names.

Explanation: The PSL language requires that all character strings appearing in statements and function calls be enclosed in double quotation marks to identify them as character strings. Improperly identified character strings will not generate compiler errors but may generate warnings about uninitialized variables if the string is not equivalent to a variable name initialized elsewhere in the program.

For example, PSL interprets the statements get(Dev); and get(RDB/Dev); as requests for the values of the user variables Dev and RDB/Dev. PSL interprets the statements get("Dev") and get("RDB/Dev") as requests for the PSL object variables Dev and RDB/Dev.

User Response: Enclose all strings in double quotation marks. Enable PslDebug flag 16 to catch variable names that were not explicitly initialized within the PSL program.

PSL Functions That Do Not Modify Their Arguments

Some PSL functions do not modify their arguments, and have no effect if their return values are not used.

Explanation: Most PSL functions do not modify the arguments passed to the function. Some of these have side effects, such as command execution or PSL object manipulation. A number of PSL functions have no effect other than the return value they generate. If the return value is not used or assigned, the statement has no effect. Functions that return modified copies of their arguments as return values can be a common source of PSL coding errors if the coder expects the argument itself to be modified.

Example of statement that has no effect:

 trim (text, "\t");

In this example, the function has a return value that is a copy of the character string variable text with all tab characters removed. The return value has no explicit destination; it is not used or assigned, and thus the return value will be discarded before executing the next PSL statement. Because the trim() function does not modify the text argument itself, the statement has no effect.

To use functions that result in a modified value of the argument as a return value, the return value should be used or assigned to a variable. If desired, the return value can be assigned to the variable that was used for the input parameter.

Examples of use or assignment of the return value:

print ( trim (text1, "\t") );
text2 = trim (text1, "\t");
text1 = trim (text1, "\t");

User Response: Become familiar with the descriptions of the PSL built-in functions. Be aware that string functions, set functions, and math functions generally do not modify their arguments and thus require that you explicitly save the return value if it is to be available to other statements within the program.

Functions That Do Not Write to the Console Window

PSL built-in functions such as grep() , cat() , or get_var() do not display their return values in the system console window.

Explanation: PSL built-in functions return their values to the PSL program. To display those values outside the program, they must be printed. For example, grep(), cat(), and get_var() produce no output to the system console window but print(grep()), print(cat()), and print(get_var()) will print the specified function return values.

User Response: To display function return values in the system console window, make those functions arguments of the print() function.

Where to go from here

Diagnosing PSL Program Errors 

Was this page helpful? Yes No Submitting... Thank you