Skip to main content

<~ Assign Or Merge

Laurence MorganAbout 1 minOperators And TokensData ManipulationAssignment

<~ Assign Or Merge

Merges the right hand value to a variable on the left hand side (expression)

Description

The Assign Or Merge operator merges your data from a the right hand side into the variable on the left hand side.

If the variable doesn't exist, then it is created.

This operator is only available in expressions.

Examples

Appending to an array

Lets say you have a directory hierarchy that looks like:

Β» tree
.
β”œβ”€β”€ a
β”‚   β”œβ”€β”€ )rPsD8Dt5EtaC4*Yyn0q
β”‚   β”œβ”€β”€ B[E3P2@gyzl2oSfvFs5(
β”‚   β”œβ”€β”€ WNYBb>B{Y:9oBNq~eVn{
β”‚   β”œβ”€β”€ W~e5bLBkGkv 2sr<XTj:
β”‚   └── lgCVRC.PkUkh(!epI(ls
β”œβ”€β”€ b
β”‚   β”œβ”€β”€ ]^[;og5$x'%Zp* TY(NR
β”‚   β”œβ”€β”€ kKcuV<9@pBrFr@"O\j?%
β”‚   β”œβ”€β”€ wX'\>V`4P=K}FaxE^Hra
β”‚   β”œβ”€β”€ yXjB#Cu'{%iLtsDCkKU%
β”‚   └── |oK7e25Dz7z&ys.?2(]E
β”œβ”€β”€ c
β”‚   β”œβ”€β”€ )Kb!TOQ]\9J6 &<Y\2qj
β”‚   β”œβ”€β”€ -X-Dm,m[JU0FZ#b0+fe+
β”‚   β”œβ”€β”€ Lw2"`S<ag{EnJ=YI8A\W
β”‚   β”œβ”€β”€ W4RUF_D.z,%M|OFsLB_A
β”‚   └── z@meR3m7h(~V4m7(V{N
β”œβ”€β”€ d
β”‚   β”œβ”€β”€ %"6Tn]&w@Uas*Gi5$?Q0
β”‚   β”œβ”€β”€ F}Ly:]zGTk}4]V+L=Wk+
β”‚   β”œβ”€β”€ z%;lf^2n0r'p0Fy?f[$j
β”‚   β”œβ”€β”€ {Iz}*#HCR_@H.KyA3=xy
β”‚   └── ~2hUs'_NftfpH`?>Bqpt
β”œβ”€β”€ e
β”‚   β”œβ”€β”€ :#'G'Rs~^~A)g,k29Er1
β”‚   β”œβ”€β”€ =N-KR9!lh"H FjCp@sP%
β”‚   └── ?,E XTt%TGD4vrvR@qXw
└── f
    β”œβ”€β”€ !B#v!iYSBmi<i6[mdlL'
    β”œβ”€β”€ _@$*?WgS0KozEnmHV*gW
    β”œβ”€β”€ eT8?OgIK@4zSHTz0$m<O
    └── |c[c-8S.;X$&UzI@jp!X

7 directories, 27 files

...and in this example you want to list the files in only directories that are vowels, you can use the Assign Or Merge operator to append to the list on each iteration for foreach:

Β» %[a,e] -> foreach d { files <~ g($d/*) }
Β» $files
[
    "a/)rPsD8Dt5EtaC4*Yyn0q",
    "a/B[E3P2@gyzl2oSfvFs5(",
    "a/WNYBb\u003eB{Y:9oBNq~eVn{",
    "a/W~e5bLBkGkv 2sr\u003cXTj:",
    "a/lgCVRC.PkUkh(!epI(ls",
    "e/:#'G'Rs~^~A)g,k29Er1",
    "e/=N-KR9!lh\"H FjCp@sP%",
    "e/?,E XTt%TGD4vrvR@qXw"
]

Please note that you can also do this with standard globbing, for example:

Β» files = g([ae]/*)

Detail

Assign Or Merge uses the same underlying algorithm as the alter -m builtin.

See Also


This document was generated from gen/expr/assign-merge-op_doc.yamlopen in new window.

Last update:
Contributors: Laurence Morgan