indirection

How to iterate over an array using indirect reference?

别来无恙 提交于 2019-11-26 17:45:28
How can I make this code work? #!/bin/bash ARRAYNAME='FRUITS' FRUITS=( APPLE BANANA ORANGE ) for FRUIT in ${!ARRAYNAME[@]} do echo ${FRUIT} done This code: echo ${!ARRAYNAME[0]} Prints APPLE . I'm tryng to do something similar but with "[@]" to iterate over the array. Thanks in advance, ${!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

Dynamic constant name in PHP

醉酒当歌 提交于 2019-11-26 17:35:31
I am trying to create a constant name dynamically and then get at the value. define( CONSTANT_1 , "Some value" ) ; // try to use it dynamically ... $constant_number = 1 ; $constant_name = ("CONSTANT_" . $constant_number) ; // try to assign the constant value to a variable... $constant_value = $constant_name; But I find that $constant value still contains the NAME of the constant, and not the VALUE. I tried the second level of indirection as well $$constant_name But that would make it a variable not a constant. Can somebody throw some light on this? http://dk.php.net/manual/en/function.constant

Calling dynamic variable in PowerShell

拥有回忆 提交于 2019-11-26 14:47:29
问题 I am trying to create a new variable that would use other variable with dynamic name as its value. Here's what I am trying to do: I have a System.Array with two values: $Years = 2015, 2016 Another variable $Transactions has a list of various transactions. I am trying to use each of those $Years values in the following way: ForEach($Year in $Years){ New-Variable -Name "Transactions_$Year" -Value $Transactions | Where {$_.Date -like "*.$Year" Now what I would like to do (within that same

Use placeholders in yaml

会有一股神秘感。 提交于 2019-11-26 12:23:46
Is there a way to use placeholders in yaml like this: foo: &FOO <<propname>>: type: number default: <<default>> bar: - *FOO propname: "some_prop" default: "some default" Context YAML version 1.2 user wishes to include variable placeholders in YAML Problem YAML does not natively support variable placeholders Anchors and Aliases do allow for some level of abstraction and indirection, but these do not work as variable placeholders that can be inserted into arbitrary regions throughout the YAML text. They must be placed as separate YAML nodes There are some add-on libraries that support arbitrary

Dynamic constant name in PHP

南楼画角 提交于 2019-11-26 05:28:52
问题 I am trying to create a constant name dynamically and then get at the value. define( CONSTANT_1 , \"Some value\" ) ; // try to use it dynamically ... $constant_number = 1 ; $constant_name = (\"CONSTANT_\" . $constant_number) ; // try to assign the constant value to a variable... $constant_value = $constant_name; But I find that $constant value still contains the NAME of the constant, and not the VALUE. I tried the second level of indirection as well $$constant_name But that would make it a

Use placeholders in yaml

拈花ヽ惹草 提交于 2019-11-26 01:59:40
问题 Is there a way to use placeholders in yaml like this: foo: &FOO <<propname>>: type: number default: <<default>> bar: - *FOO propname: \"some_prop\" default: \"some default\" 回答1: 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 do allow for some level of

What is indirect expansion? What does ${!var*} mean?

戏子无情 提交于 2019-11-25 23:16:33
问题 I\'m reading \" Bash Guide for Beginners \". It says: If the first character of PARAMETER is an exclamation point, Bash uses the value of the variable formed from the rest of PARAMETER as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution, rather than the value of PARAMETER itself. This is known as indirect expansion. The example given is: franky ~> echo ${!N*} NNTPPORT NNTPSERVER NPX_PLUGIN_PATH I don\'t quite understand here: the