As I was sure I had seen it before I now just had a look...Borut wrote:I was not able to find the relevant description in the on-line help (if there already is one about "", then it should perhaps be made more visible (what Don is going to do)),
In Scripting Commands Reference, under description of the global command, you read:
Code: Select all
variable(s)
A single variable, or a comma-separated list of up to 10 variables. If a
variable has already been defined as global before, then the global
command initializes it to its current global value, else it is initialized to an
empty string.
And note: here Don talks about the definition of a global variable.
If it's not (yet) defined as global, it's not global, it's undefined, and it's not initialized.
If it is defined global, it's global, it's defined, and it may be initialized or not.
So, for a global variable, it can be defined but uninitialized. But you can not use it undefined - as then it's not a global.
A non-global variable, if necessary, is implicitly defined by assigning it a value. But if you reference it without assigning a value before, you reference a non-defined variable! Something that never can happen with a global variable.
Now reference of a non-defined variable shows the name of the variable, while reference of a defined but uninitialized variable shows "".
If you could define a normal variable without assigning it a value, it should show "", too.
So there is some logic with the way it works...
And as last to my code-snippet: If you assign the name of a variable to that variable, you don't "un-define" it, or empty it! It looks the same as if it would be not defined - but it's filled with a string of characters! For this you might read the definition of the unset command. The same is for setting a (global) variable to "".
I remember another scripting language having a function defined() (or so) to test for the definition-status of a variable - you supply a variable name, and it returns something like undefined / variable / global. (You still have a problem with a global containing "": is it un-initialized, or is it set to empty?)
XYplorer Beta Club