Local Variable Enhancement

The Local variables implementation must not destabilize the scripting language and must not impose long and complex code development. Therefore, the dataset structure is used to support local variables. The script execution fails if local variable has the same name as a parameter in the current working dataset. Considering that a local variable is a parameter in the dataset, script fails if the same local variable is defined and set multiple times in the same execution context. A typical example is defining and setting a local variable in a PROC statement with a recursive call.

LOCAL:

Syntax:

LOCAL: ListName0 [, ListName1 [, ListName2 [...]]], where

ListName1... ListNameN are ListSpec.

Command Description

The command indicates the entry defined by ListNames in the NVSet as local variables.

The variables must not exist in the dataset NVSet when the LOCAL: command is processed, either as normal NVSet entries or as local entries. The variables are removed from the NVSet at the end of the current IF, ELIF, ELSE, WHILE, PROC, or at the end of the current top-level script.

Examples of Local Variable:

LOCAL:myLocalVar1,myLocalVar2 

    # These will be removed at end of current block. 
    # 
    FORMAT:<myLocalVar1>=tempValue 
    FORMAT:<myLocalVar2>=abc_<myLocalVar1>_<SomeOtherVar> 
    ... 
           
      IF:<someVar>==<myLocalVar1> 
        LOCAL:myLocalVar3 
        FORMAT:<myLocalVar3>=abcd 
      FI: 

      # Here, myLocalVar3 does not exist anymore in the NVSet. 
      # 
      ... 
        

The LOCAL command does not create the entry in the NVSet:. The local values can be manipulated and populated as normal NVSet values. The local values are NVSet values, and therefore accessible by the CALL_CODE NVSet access. The only difference is that they are automatically removed at the end of block.

The local variables have fully scoped names because they are defined in the default NVSet and accessible by other methods. For example, the name of a local variable in a procedure must contain the name of the procedure. This ensures that no calling script or procedure uses the same name. The checks and validation is performed at runtime.

LOCAL:X 
          IF:<str>==abc 
              FORMAT:<X>=3 
          FI: 

          # The following instruction will only fail if str == "abc", as 
          # only in this case X is populated. 
          # 
          LOCAL:X

Comma Usage in the Command

Use comma to separate the arguments for the commands with several arguments, such as FORMAT_LIST, UNDEF_LIST, INDEX_OF, SUBSTRING, SPLIT, etc.

The following are the constraints to use commas:

  • Name of data in ParamSpec must not contain commas.
  • If the fixed parts of TemplateString contain commas, write the octal value \054.

Configuration

The configuration parameters used during initialization are defined in the CmdConfig entity, which inherits from guardeval::TemplateConfig.

The parameters of variables defined in the guardeval::TemplateConfig set:

Parameter Description
maxLoopIterations

To avoid infinite loops when evaluating commands the do loops (WHILE), this parameter defines the maximum number of loops allowed. In case the number of loops exceed this value, an error will be generated.

By default, this is 1000. This parameter is used only during evaluation.

maxCallIterations

To avoid infinite loops when evaluating procedures which call other procedures, this parameter defines the maximum number of calls allowed. In case the number of calls exceed this value, an error will be generated.

By default, this is 10. This parameter is used only during evaluation.

callDefinedProcedure

Flag to force defining procedures before calling them.

With this flag set to true, the CALL_PROC:ProcName command must be set after the PROC:ProcName procedure definition. If it is set before, this will generate an error during initialization.

This parameter is used only during initialization.

commandEntryName Name of the entry in the NVSet to use with the FORMAT_COMMAND command. By default, this is #COMMAND#.