Does the standard mandate an lvalue-to-rvalue conversion of the pointer variable when applying indirection?

I think you’re approaching this from a rather oblique angle, so to speak. According to ยง5.3.1/1: The unary * operator performs indirection: the expression to which it is applied shall be a pointer to an object type, or a pointer to a function type and the result is an lvalue referring to the object or … 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

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”.

If Statement Against Dynamic Variable [duplicate]

Replace if (“state_$name” -eq “True”) { with: if ((Get-Variable -ValueOnly “state_$name”) -eq “True”) { That is, if your variable name is only known indirectly, via an expandable string, you cannot reference it directly (as you normally would with the $ sigil) – you need to obtain its value via Get-Variable, as shown above. However, as … Read more

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

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