Re: Another try, do_request and globals issues

Grzegorz Adam Hankiewicz <[email protected]> Mon, 18 Aug 2003 11:09:44 +0200
Newsgroups gmane.comp.web.tclwebtest
Message-ID <[email protected]>
On 2003-08-08, Gordon Molek <[email protected]> wrote:
> Secondly, I am still having trouble with globals. [...]
>
>  #! /cygdrive/c/tcl/bin/tclsh.exe
>  proc dumb_proc {} {
>      set myvar 4
>      puts "The value of the local variable is $myvar"
>  
>      global myglobalvar
>      puts "The value of the global variable is $myglobalvar"
>  }
>  
>  set myglobalvar 79
>  dumb_proc
>
> [...]  Does tclwebtest do something that interferes with global
> variables?  [...]

Yes it does. Basically the first thing you run is in the
global namespace, `set myglobalvar 79' therefore sets a global
variable. However, when you run the same script from tclwebtest,
it's tclwebtest which is running in the global namespace, and your
script is being run in another namespace because it is being run
inside an `eval'.

Maybe tclwebtest could be modified to run inside a custom namespace
and then run the script with an `upvar' instead. Til, what do
you think?

Anyway, the solution to your problem is easy, before `set myglobalvar
79' put another `global myglobalvar' and it will work as expected:

   $ ./tclwebtest test 
   
   ----- START: test at [18/ago/2003:10:57:59] -----
   The value of the local variable is 4
   The value of the global variable is 79
   ----- SUCCESS: test (took 0s)               -----
   
   DURATION: 0

-- 
 Grzegorz Adam Hankiewicz, [email protected] Tel: +34-94-472 35 89.
 eFaber SL, Maria Diaz de Haro, 68, 2         http://www.efaber.net/
 48920 Portugalete, Bizkaia (SPAIN)


-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01