docs/src/reference-dsl-operators.md
Operators are listed on the DSL built-in functions page.
Operators are listed in order of decreasing precedence, from highest to lowest.
| Operators | Associativity |
|---|---|
() {} [] | left to right |
** | right to left |
??? | left to right |
?? | left to right |
! ~ unary+ unary- | right to left |
. | left to right |
* / // % | left to right |
binary+ binary- | left to right |
<< >> >>> | left to right |
& | left to right |
^ | left to right |
| ` | ` |
< <= > >= | left to right |
== != =~ !=~ <=> | left to right |
&& | left to right |
^^ | left to right |
| ` | |
? : | right to left |
= | N/A for Miller (there is no $a=$b=$c) |
See also the section on parsing and operator precedence in the REPL for information on how to examine operator precedence interactively.
Functions are often pass-throughs straight to the system-standard Go libraries.
The min and max functions are different from other multi-argument functions, which return null if any of their inputs are null: for min and max, by contrast, if one argument is absent-null, the other is returned. Empty-null loses min or max against numeric or boolean; empty-null is less than any other string.
Symmetrically with respect to the bitwise OR, AND, and XOR operators
|,
&, and
^, Miller has logical operators
||,
&&, and
^^.
The exponentiation operator ** is familiar from many languages, except that an integer raised to an int power is int, not float.
The regex-match and regex-not-match operators =~ and !=~ are similar to those in Ruby and Perl.
The main use for the . operator is for string concatenation: "abc" . "def" is "abc.def".
However, in Miller 6, it has an optional use for map traversal. Example:
<pre class="pre-highlight-in-pair"> <b>cat data/server-log.json</b> </pre> <pre class="pre-non-highlight-in-pair"> { "hostname": "localhost", "pid": 12345, "req": { "id": 6789, "method": "GET", "path": "api/check", "host": "foo.bar", "headers": { "host": "bar.baz", "user-agent": "browser" } }, "res": { "status_code": 200, "header": { "content-type": "text", "content-encoding": "plain" } } } </pre> <pre class="pre-highlight-in-pair"> <b>mlr --json --from data/server-log.json put -q '</b> <b> print $req["headers"]["host"];</b> <b> print $req.headers.host;</b> <b>'</b> </pre> <pre class="pre-non-highlight-in-pair"> bar.baz bar.baz </pre>This also works on the left-hand sides of assignment statements:
<pre class="pre-highlight-in-pair"> <b>mlr --json --from data/server-log.json put '</b> <b> $req.headers.host = "UPDATED";</b> <b>'</b> </pre> <pre class="pre-non-highlight-in-pair"> [ { "hostname": "localhost", "pid": 12345, "req": { "id": 6789, "method": "GET", "path": "api/check", "host": "foo.bar", "headers": { "host": "UPDATED", "user-agent": "browser" } }, "res": { "status_code": 200, "header": { "content-type": "text", "content-encoding": "plain" } } } ] </pre>A few caveats:
. has higher precedence than + in the table above -- in Miller 5 and below, where . was only used for concatenation, it had the same precedence as +. So you can now do this:. for map-traversal as well as string-concatenation in the same statement, you'll need to insert parentheses, as the default associativity is left-to-right: