Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

upvar bad level error

431 views
Skip to first unread message

jemptymethod

unread,
Jul 23, 2010, 6:55:43 AM7/23/10
to
Somebody suggested the following code to me for debugging an http
request:

package require http
set tok [http::geturl http://localhost:1565/pgn4desk.htm]
upvar $tok token
set token(body) ""
parray token

However it results in the following error. I still haven't wrapped my
head around upvar :( Hopefully in the near future as I use Tcl more
and more. Thanks in advance for any guidance:

$ ./tclkit-cli pgn4desk.vfs/debug.tcl
bad level "::http::1"
while executing
"upvar $tok token"
(file "pgn4desk.vfs/debug.tcl" line 3)

Uwe Klein

unread,
Jul 23, 2010, 7:09:17 AM7/23/10
to

# there is no level further up than (the current) toplevel scope thus
# upvar wants that optional level argument:
upvar #0 $tok token

set token(body) ""
parray token

#or


package require http
set tok [http::geturl http://localhost:1565/pgn4desk.htm]

set ${tok}(body) ""
parray $tok

uwe

Alexandre Ferrieux

unread,
Jul 23, 2010, 8:11:16 AM7/23/10
to
On Jul 23, 1:09 pm, Uwe Klein <uwe_klein_habertw...@t-online.de>
wrote:

> jemptymethod wrote:
> > Somebody suggested the following code to me for debugging an http
> > request:
>
> > package require http
> > set tok [http::geturlhttp://localhost:1565/pgn4desk.htm]

> > upvar $tok token
> > set token(body) ""
> > parray token
>
> > However it results in the following error.  I still haven't wrapped my
> > head around upvar :(  Hopefully in the near future as I use Tcl more
> > and more.  Thanks in advance for any guidance:
>
> > $ ./tclkit-cli pgn4desk.vfs/debug.tcl
> > bad level "::http::1"
> >     while executing
> > "upvar $tok token"
> >     (file "pgn4desk.vfs/debug.tcl" line 3)
>
> package require http
> set tok [http::geturlhttp://localhost:1565/pgn4desk.htm]

> # there is no level further up  than (the current) toplevel scope thus
> # upvar wants that optional level argument:
> upvar #0 $tok token
>
> set token(body) ""
> parray token
>
> #or
> package require http
> set tok [http::geturlhttp://localhost:1565/pgn4desk.htm]

> set ${tok}(body) ""
> parray $tok
>
> uwe

Note that the confusing error message

bad level "::http::1"

is now (8.6) replaced by the accurate

bad level "1"

since the root cause of the problem is the fact that, without an
explicit level, upvar assumes [upvar 1] (meaning one up), which here
is invalid as you said, since we're already at toplevel.

This message improvement was part of the fix for bug 2673163:

https://sourceforge.net/tracker/index.php?func=detail&aid=2673163&group_id=10894&atid=110894

-Alex

0 new messages