Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 343023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:51:31+00:00 2026-05-12T10:51:31+00:00

How do I create and iterate through a hash of hashes in TCL? If

  • 0

How do I create and iterate through a hash of hashes in TCL?

If I have data like:

foo = {
    a => {
        aa => { aa1 aa2 aa3 }
        ab => { ab1 ab2 ab3 }
        ac => { ac1 ac2 ac3 }
    }
    b => {
        ba => { ba1 ba2 ba3 }
        bb => { bb1 bb2 bb3 }
        bc => { bc1 bc2 bc3 }
    }
    c => {
        ca => { ca1 ca2 ca3 }
        cb => { cb1 cb2 cb3 }
        cc => { cc1 cc2 cc3 }
    }
}

How do I create such a hash by inserting one leaf-node data item at a time. Something like:

lappend foo(a)(ab) “ab1”

Then how do I iterate over all data elements? like:

foreach key in foo {
    foreach sub_key in foo($key) {
        foreach elem in foo($key)($sub_key) {
            puts "foo\($key\)\($sub_key\) is $elem"
        }
    }
}

Edit :
Unfortunately, I do not have access to the newer ‘dict’ construct.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:51:32+00:00Added an answer on May 12, 2026 at 10:51 am

    If you’re not using Tcl 8.5, then you can use arrays. Note that arrays are one-dimensional, but the key is an arbitrary string that can be used to fake multi-dimensionality:

    array set foo {}
    foreach first {a b c} {
        foreach second {a b c} {
            foreach third {1 2 3} {
                lappend foo($first,$first$second) "$first$second$third"
            }
        }
    }
    parray data
    

    and output it — note: array keys, unlike dictionary keys, are unordered:

    foreach key [array names foo] {
        foreach elem $foo($key) {
            puts "$key\t$elem"
        }
    }
    

    If you are given the keys (example ‘b’ and ‘bc’) you can get the value thusly:

    set key1 b
    set key2 bc
    foreach elem $foo($key1,$key2) {puts $elem}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey! I iterate through a hash with @lists.each do |list|. I create a div
I need to create feature which will iterate through all subsites of site collection
I have an issue dealing with a hash of objects. My hashes are player
I'm trying to create a template function which will iterate through the map's specified
I have code using boost to list directory contents, iterate through each file, and
I want to create a method that would iterate through a keyed collection. I
Possible Duplicate: iterate through pairs of items in python list I have a list
I have some code in jQuery that iterate through children in div using each().
Let's say I have a bunch of items and I want to iterate through
I'm trying to create an export Excel/CSV function that will iterate through a custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.