Empty strings and 'env' array weirdness 
Author Message
 Empty strings and 'env' array weirdness

Folks,

Here's three lines of TCL code that have me perplexed:

% set env(whatever) ""                # set to an empty string
% info exists env(whatever)         # Does it exist.... Yup
1
% puts $env(whatever)                # Or does it?
can't read "env(whatever)": no such variable

A 'parray' on env also shows that env(whatever) doesn't exist.  If I use any other array, the 'puts' echoes a blank line.  Or, if the string contains one of more spaces, all is OK too.

Of course 'env' is an array that Tcl handles differently than 'normal' arrays.  But env's behavior with empty strings is something I find somewhat unexpected.

( Details:  Windows XP,  Tcl 8.3.5 )

--
Ronald J. Maddalena



Tue, 16 May 2006 14:52:00 GMT  
 Empty strings and 'env' array weirdness

Quote:

> Folks,

> Here's three lines of TCL code that have me perplexed:

> % set env(whatever) ""                # set to an empty string
> % info exists env(whatever)         # Does it exist.... Yup
> 1
> % puts $env(whatever)                # Or does it?
> can't read "env(whatever)": no such variable

> A 'parray' on env also shows that env(whatever) doesn't exist.  If I use any other array, the 'puts' echoes a blank line.  Or, if the string contains one of more spaces, all is OK too.

> Of course 'env' is an array that Tcl handles differently than 'normal' arrays.  But env's behavior with empty strings is something I find somewhat unexpected.

> ( Details:  Windows XP,  Tcl 8.3.5 )

               ^^^^^^^^^^^
Hi Ronald,

afaik, Windows handles empty environment variables as non-existant.
Try your example on a real OS and it will work.

Best regards

Ulrich

--

For those of you who don't get this e-mail, let me know and I'll re-send it.



Tue, 16 May 2006 18:18:21 GMT  
 Empty strings and 'env' array weirdness
Hello Ronald,

sorry to say, but, except from "info exists ...", everything is
allright!

Microsoft platforms, environments work this way:

    inside the command shell:

        C:\> set a=a
        C:\> set a
        a=a
        ALLUSERSPROFILE=G:\Dokumente und Einstellungen\All Users
        APPDATA=G:\Dokumente und Einstellungen\ml\Anwendungsdaten
        AVENGINE=G:\PROGRA~1\CA\SHARED~1\SCANEN~1
        C:\> set a=
        C:\> set a
        ALLUSERSPROFILE=G:\Dokumente und Einstellungen\All Users
        APPDATA=G:\Dokumente und Einstellungen\ml\Anwendungsdaten
        AVENGINE=G:\PROGRA~1\CA\SHARED~1\SCANEN~1

    inside the tcl shell:

        % set env(a) "a";
        % puts $env(a);
        a
        % set env(a) "";
        % puts $env(a);
        can't read "env(a)": no such variable

This is right, if you consider the default behaviour of Microsoft
environment variables.

On Unix, I tried it on AIX, HP-UX, IRIX and Solaris, it works like
expected!
But on UNIX a ...

    setenv a ""

... will work!

The bug is more or less, that "info exists" tells, that this env array
element exists. Even if it is non-existent.

I don't know exactly how "set env(name) ?data?" works.

But if "set env(name) data" works directly on "putenv( "name=data" )",
than an environment variable will be deleted on Microsoft platforms,
if "data" is empty.
On the same side the env array element seem to be created with "data",
even if "data" is empty.

"info exists env(name)" will return true.

Asking for the contents of the env array could access dynamicly via
"getenv( name ) the environment and so the empty environment variable
will be non-existent. And the local copy of the environment will be
ignored.

If all accesses on the global env array would be dynamic, than there
has been no need for the local copy, the array hashtable, where "info
exists env(name)" asks for array element existence.

Right?

Best regards,

Martin Lemburg


Quote:
> Folks,

> Here's three lines of TCL code that have me perplexed:

> % set env(whatever) ""                # set to an empty string
> % info exists env(whatever)         # Does it exist.... Yup
> 1
> % puts $env(whatever)                # Or does it?
> can't read "env(whatever)": no such variable

> A 'parray' on env also shows that env(whatever) doesn't exist.  If I use
> any other array, the 'puts' echoes a blank line.  Or, if the string
> contains one of more spaces, all is OK too.

> Of course 'env' is an array that Tcl handles differently than 'normal'
> arrays.  But env's behavior with empty strings is something I find
> somewhat unexpected.

> ( Details:  Windows XP,  Tcl 8.3.5 )



Tue, 16 May 2006 19:09:32 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Empty array challenge ''=i.0

2. can't read env(DISPLAY) from regexp with $env(DISPLAY)

3. parsing ENV['PATH']

4. ENV['HOME'] on win32

5. unshifting a directory onto ENV['PATH']

6. STRING 'make'/'remake'

7. Getting Ascii string from hex 'string'

8. Inserting '\t;' between empty curly braces

9. 'array of array' declaration

10. (subtypep '(simple-array character (*)) '(array character (*)))

11. (typep (make-array 10 :element-type 'bit) '(array bit (10)))

12. os.listdir ('.'): Solaris: returns empty list in directory with 215 files

 

 
Powered by phpBB® Forum Software