#### 37.6.7 Using indirection in expressions

Suppose you assign a variable to another variable, as follows:

    <$$myvar = $$other>

Then, if you subsequently use:

    <$$myvar>

you get whatever contents the variable named $$other had at the time you assigned it to the variable named $$myvar. Suppose you specified the original assignment like this:

    <$$myvar = "$$other">

Then, if you subsequently use:

    <$$myvar>

all you get is the literal string “$$other”. If instead you use:

    <*$$myvar>

you get the current contents of the variable $$other (but if there were no variable named $$other, you would get just the literal string “$$other”).

The same thing works through multiple layers. If you use this series of assignments:

    <$$myvar = "$$other">
    <$$other = "$$whatever">
    <$$whatever = "here">

then, subsequently, the contents of <*$$myvar> is “here”, which is the same as the contents of <*$$other>, or of <$$whatever>, or even of <*$$whatever>.

Now if you set:

    <$$other = "something">

then:

    <$$myvar>    gives:   $$other
    <*$$myvar>   gives:   something

If next you set:

    <*$$myvar = "something else">

then:

    <$$other>    gives:   something else
    <$$myvar>    gives:   $$other
    <*$$myvar>   gives:   something else

If finally you set:

    <$$other = "$$myvar">

then (oops!):

    <$$other>    gives:   nothing

Runaway-prevention limit

However, a built-in circular-reference counter saves you from the natural consequences of this last foolish assignment. The counter prevents indirection through more than 128 levels.

The top-level variable is like an envelope that can contain more nested envelopes; you continue opening them until you get to the letter (the contents). You can use indirection to recurse, to process variables and expressions, and so forth, down to a simple value, through whatever layers that takes.

Previous Topic: 37.6.6 Using list variables in expressions

Next Topic: 37.6.8 Removing spaces from strings: an example

Parent Topic: 37.6 Using expressions in macros

Sibling Topics:

37.6.1 Understanding macro expressions

37.6.2 Understanding operands and operators

37.6.3 Displaying expression results in output

37.6.4 Using control structures in expressions

37.6.5 Specifying substrings in expressions

37.6.6 Using list variables in expressions

37.6.8 Removing spaces from strings: an example