$scalar

Retrieve a collection of all scalar members of a Struct, or assign a scalar value to a Struct.

Struct->$scalar

Return Values

Returns a reference to all scalar members of a Struct.

Common Values Returned in $procerror after $scalar

Value

Error Constant

Meaning

-1163

USTRUCTERR_SCALAR

Tried to access members of a Scalar Struct, which has no members

-1164

USTRUCTERR_NOT_A_SCALAR

Tried to assign a non-scalar value to $scalar. The Struct is not changed in that case.

Description

A Struct node can have one or more members that are scalar Structs. You can use $scalar to retrieve all scalar members of a Struct node (instead of iterating over them and checking $isScalar for each of them). You can also use $scalar to assign or change the scalar value of a Struct.

For more information, see Struct Leaves.

Example: Using $scalar

For example, given the following Struct (referenced by Struct variable vStruct):

[]
  [div]
    [h1] = "Example"
    "Text can be "
    [b] = "bold "
    "or " 
    [em] = "italic"

the following code shows how you can use $scalar:

>
variables
  struct vStruct, vScalar1, vScalar2
endvariables
  ...  
  vScalar1 = vStruct->div->$scalar     Callout 1
  vScalar2 = vStruct->div->b->$scalar  Callout 2

  vStruct->div->$scalar = "Plain "     Callout 3
  1.  vScalar1 refers to two Scalar Structs: "Text can be " and "or "
  2.  vScalar2 refers to one Scalar Struct: "bold "
  3.  A new value is assigned to $scalar, which is inserted at the position of the first scalar Struct in vStruct. vStruct now has the following structure:
    []
      [div]
        [h1] = "Example"
        "Plain "
        [b] = "bold "
        [em] = "italic"
    
History

Version

Change

9.5.01

Introduced

Related Topics