What does the quote “An extra level of indirection solves every problem” mean? [closed]

Generally it means that by increasing the level of abstraction one can make the problem easier to understand/resolve. Be careful with your abstractions though, the full quote at least as I heard it is, “You can solve every problem with another level of indirection, except for the problem of too many levels of indirection”.

Assign to a bash array variable indirectly, by dynamically constructed variable name

arr$varEnvCol[$index]=”$(…)” doesn’t work the way you expect it to – you cannot assign to shell variables indirectly – via an expression that expands to the variable name – this way. Your attempted workaround with eval is also flawed – see below. tl;dr If you use bash 4.3 or above: declare -n targetArray=”arr$varEnvCol” targetArray[index]=$(echo $line | … Read more

Create an incrementing variable from 2 variables in PowerShell

You’re looking for variable indirection, i.e. the ability to refer to a variable indirectly, by a name stored in another variable or returned from an expression. Note, however, that there are usually superior alternatives, such as using arrays or hashtables as multi-value containers – see this answer for an example. If you do need to … Read more

Calling dynamic variable in PowerShell

First of all, your New-Variable invocation doesn’t do what you think it does, as you’d pipe the output of New-Variable to Where-Object instead of using the value of $Transactions | Where … as value for the variable. You need parentheses for that to work: New-Variable -Name “Transactions_$Year” -Value ($Transactions | Where {$_.Date -like “*.$Year” }) … Read more

How to iterate over an array using indirect reference?

${!ARRAYNAME[@]} means “the indices of ARRAYNAME“. As stated in the bash man page since ARRAYNAME is set, but as a string, not an array, it returns 0. Here’s a solution using eval. #!/usr/bin/env bash ARRAYNAME=’FRUITS’ FRUITS=( APPLE BANANA ORANGE ) eval array=\( \${${ARRAYNAME}[@]} \) for fruit in “${array[@]}”; do echo ${fruit} done What you were … Read more

Use placeholders in yaml

Context YAML version 1.2 user wishes to include variable placeholders in YAML have placeholders replaced with computed values, upon yaml.load be able to use placeholders for both YAML mapping keys and values Problem YAML does not natively support variable placeholders. Anchors and Aliases almost provide the desired functionality, but these do not work as variable … Read more

tech