Can't get element of array

From: Alexander Danilov (alex_at_fssg.st-oskol.ru)
Date: 07/25/04


Date: Sun, 25 Jul 2004 16:52:47 +0400

Help please.
I can't find rational explanation of the following error:

---------cut here------------
extension example => 9849
iMap: an indexed map viewer => 8771
If we had no proc => 5892
NSIface => 5354
) => 991
Randy Kunkee => 1828
* => 4255
can't read "t(+)": no such element in array
     while executing
"set a $t($name)"
     ("foreach" body line 2)
     invoked from within
"foreach name [array names t] {
     set a $t($name)
     puts "$name => $a"
     if {[llength $a] == 1} {
         array unset t $name
     }
}"
     (file "./demo.tcl" line 18)
---------cut here------------
during runing the folowing script:
---------cut here------------
#! /bin/sh
# \
exec tclsh "$0" "$@"

package require Mk4tcl

mk::file open wiki wikit.tkd -readonly

array set t {}
foreach i [mk::select wiki.pages] {
     set name [mk::get wiki.pages!$i name]
     lappend t($name) $i
}

#parray t
puts "-------------------------------------"

foreach name [array names t] {
     set a $t($name)
     puts "$name => $a"
     if {[llength $a] == 1} {
         array unset t $name
     }
}

puts "-------------------------------------"
puts [array get t]

---------cut here------------

I can't understand why I can't get element with index "+".
I am absolutely sure, than array "t" has element with index "+"
(uncomment parray t).
Is it bug in Tcl?

wikit.tkd - it's a local copy of Tcl Wiki

P.S.: OS - Debian Linux v3.0 (woody), Tcl v8.4.6, Mk4tcl v2.4.9.3



Relevant Pages

  • Re: [PHP] foreach() using current() strange beahvior
    ... that's expected as foreach moves the internal array pointer, ... When using the internal pointer just by calling current(so not moving ... Unless the array is referenced, foreach operates on a copy of the ...
    (php.general)
  • Re: a question about for and foreach
    ... foreach (@array) { ... why @array are changed after this foreach loop!!! ... The "foreach" loop iterates over a normal list value and sets the ... If any element of LIST is an lvalue, you can modify it by modifying ...
    (perl.beginners)
  • Re: safe to delete elements of array in foreach
    ... I agree with Jon on this one. ... I make it a habit not to delete entries in a foreach() loop. ... build an array of keys I want to delete, and after the loop ends, delete ... I don't know whether an operation like this is guaranteed to work in PHP ...
    (comp.lang.php)
  • Re: [PHP] Foreach
    ... The problem I am having is getting both to update the table in MySQL. ... echo "$t"; ... foreach { ... // foreach expects an array, ...
    (php.general)
  • Re: safe to delete elements of array in foreach
    ... (normally this is not the case but not sure in php) ... I make it a habit not to delete entries in a foreach() loop. ... build an array of keys I want to delete, and after the loop ends, ...
    (comp.lang.php)