The string is based on the referenced variable.
- If the variable is a hash, the string is HASH.
- If the variable is an array, the string is ARRAY.
- If the variable contains an array, the string is REF.
- ...
- Otherwise, the string is SCALAR.
So,
- You are printing a reference to $a, which contains "foo": SCALAR
- You are printing a reference to $a, which contains \$a: REF
- You are printing a reference to $b, which contains "foo": SCALAR
- You are printing a reference to $a, which contains \$a: REF