Operator Semantics

The following sections list all the operators and their semantic depending on the types of the operands. The left column represents the left-hand side operand type while the top row represents the right-hand side operand type. The values describe the semantic of the operation or list error if the corresponding operator cannot be applied with the given operand types.

Arithmetic Operators
Collection and Array Operators
Regular Expression-Include Operators
Relational and Equality Operators
Logical Operators
Unary Operators

Arithmetic Operators

The following arithmetic operators are covered in this section:

+
-
*
/
%
^

+

“+” Arithmetic Operator

+

Number

String

Array

Hash

Res Collection

Other

Number

Addition

Error

Error

Error

Error

Error

String

Concatenation

Concatenation

Error

Error

Error

Error

Date/Time

Addition (seconds)

Error

Error

Error

Error

Error

Array

Error

Error

Concatenation

Error

Error

Error

Hash

Error

Error

Error

merge left into right

Error

Error

Res Collection

Error

Error

Error

Error

Concatenation

Error

Other

Error

Error

Error

Error

Error

Error

-

“-” Arithmetic Operator

-

Number

Date/Time

Array

Res Collection

Other

Number

Subtraction

Error

Error

Error

Error

Date/Time

Subtraction (seconds)

Subtraction (seconds)

Error

Error

Error

Array

Error

Error

Array Difference

Error

Error

Res Collection

Error

Error

Error

Coll Difference

Error

Other

Error

Error

Error

Error

Error

*

“*” Arithmetic Operator

*

Number

Other

Number

Multiplication

Error

Other

Error

Error

/

“/” Arithmetic Operator

/

Number

Other

Number

Division (integral, if both numbers are integers)

Error

Other

Error

Error

%

“%” Arithmetic Operator

%

Number

Other

Number

Modulo (non integer numbers are rounded)

Error

Other

Error

Error

^

“^” Arithmetic Operator

-

Number

Other

Number

Power

Error

Other

Error

Error

Collection and Array Operators

The following collection and array operators are covered in this section:

<<
[ ]
[ ]=

<<

“<<” Collection and Array Operator

<<

All

Array

Append object in right-hand side to array in left-hand side

Other

Error

[ ]

The slice operator returns elements of an array, a hash or a resource collection using an index or a range (array and resource collection) or a key (hash). A range is specified using x..y where x and y are optional (no x means from the start of the array or collection, no y means to the end of the array or collection).

Note:Retrieving elements of a resource collection creates a new resource collection consisting of these elements.

“[ ]” Collection and Array Operator

[ ]

Number

String

Range

Other

Res Collection

Creates a new collection consisting of the element at a given index

Error

Creates a new collection consisting of the element in the given range (x..y where x and y are optional)

Error

Array

Value at given index

Error

Creates a new array consisting of the element in the given range (x..y where x and y are optional)

Error

Hash

Error

Value associated with given key if any, null otherwise

Error

Error

String

Creates a string composed of a character at a given index

Error

Create a string made of characters in the given range. Range bounds may have negative values (from last or from beginning).

Error

Other

Error

Error

Error

Error

[ ]=

The slice assign operator replaces an element of an array, hash or resource collection or a range of an array or resource collection with given elements.

“[ ] =” Collection and Array Operator

[ ] =

Number

String

Range

Other

Res Collection

Replaces the resource at a given index. Right-hand side must be a resource collection.

Error

Replace elements in the given range with elements of the right-hand side resource collection.

Error

Array

Replace the value at a given index.

Error

Replace the elements in the given range with elements of the given array. The right-hand side must be an array.

Error

Hash

Error

Replace/set the value associated with a given key.

Error

Error

Other

Error

Error

Error

Error

Regular Expression-Include Operators

The following regular expression-include operators are covered in this section:

=~
!~

=~

“=~” Regular Expression-Include Operator

=~

String

Array

Other

String

true if regular expression given in right-operand matches string given in left operand

Error

Error

Array

true if array contains string

true if array contains array

true if array contains value

Hash

true if hash has that key

Error

Error

Other

Error

Error

Error

The right-hand side of a regular expression comparison may use the symbol / to delineate the pattern. The ending / may be followed by the following options:

i for case insensitive matching
m for multi-line string matching
x for extended syntax support (whitespaces in the pattern are ignored)

Examples

"foo" =~ "foo" # true 

"foo" =~ /foo/ # true 

"foo" =~ /FOO/i # true 

!~

a !~ b is equivalent to !(a =~ b).

Relational and Equality Operators

The following relational and equality operators are covered in this section:

==, !=
<, <=, >, >=

==, !=

Equality comparison is done recursively if values are arrays or hashes.

“==” Relational and Equality Operator

==

All

All

true if operands have same value, false otherwise

<, <=, >, >=

“<” Relational and Equality Operator

<

Number

String

Date/Time

Res Collection

Array

Other

Number

Less than

Error

Error

Error

Error

Error

String

Error

Lexicographical less than

Error

Error

Error

Error

Date/Time

Error

Error

Less than

Error

Error

Error

Res Collection

Error

Error

Error

@a < @b: true if all elements of @a are also elements of @b.

Error

Error

Array

Error

Error

Error

Error

@a < @b: true if all elements of @a are also elements of @b.

Error

Other

 

 

 

 

 

Error

Note:>, <=, and >= are omitted for brevity (greater than, lesser or equal than, greater or equal than, respectively).

Logical Operators

The following logical operators are covered in this section:

&
&&
|
||

&

“Bitwise and”. Applied to resource collections (or arrays) it returns all elements that appear in both resource collections (or arrays).

“&” Logical Operator

&

false

null

true

Array

Res Collection

Other

false

false

false

false

false

false

false

null

false

false

false

false

false

false

true

false

false

true

true

true

true

Array

error

error

error

intersection of two arrays

error

error

Res Collection

error

error

error

error

new collection with common hrefs or error if collections are of different types

error

Other

error

error

error

error

error

error

&&

“Logical and”. Returns the right-hand side operand if the left-hand side is neither false nor null (otherwise returns left-hand side operand). In the following table, (1) and (2) refer to the position of that particular argument in the expression.

“&&” Logical Operator

&&

false

null

true

Other (1)

false

false

false

false

false

null

null

null

null

null

true

false

null

true

(1)

Other (2)

false

null

true

(2)

|

“Bitwise or”. Applied to resource collections (or arrays), returns all elements that appear in either resource collection (or array).

Note:The “|” operator differs from the “+” operator when applied to a collection. “|” will produce only one instance of each element in each collection even if the same element appears in both.

“|” Logical Operator

|

false

null

true

Other

false

false

false

true

true

null

false

false

true

true

true

true

true

true

true

Other

error

error

error

error

||

“Logical or”. Returns the left-hand side operand if it is neither false nor null (otherwise returns right-hand side operand). In the following table, (1) and (2) refer to the position of that particular argument in the expression.

“|” Logical Operator

||

false

null

true

Other (2)

false

false

null

true

(2)

null

false

null

true

(2)

true

true

true

true

true

Other (1)

(1)

(1)

(1)

(1)

Unary Operators

The following unary operators are covered in this section:

-
!

-

“-” is the unary minus operator.

“-” Unary Operator

-

Value

Number

Opposite value

Other

Error

!

! is the logical not operator.

Note:“!” applies to all types (negating a non-boolean value returns true if it is either false or null, false otherwise).

“!” Unary Operator

!

Value

false

true

null

true

Other

false