Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
How to use an array in switch statements?

Is it allowed to use an array element using tcl switch statement? I have an array named

set name "pad"
set p_list("pad") "IO2"

and now trying to do some conditional based stuff on that array like

 % switch $p_list($net_name) {
      IO1 {
           puts "io1"
      }
      IO2 {
         puts "io2"
      }
      default {
         puts "default"
      }
    }

but it seems array can't be passed to switch and therefore, erroring out with following error can't read "pads_list(pad)": no such element in array

Could someone please suggest if it's allowed or not. If, allowed then how can I make it work?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Double quotes are not special in Tcl when not at the start or end of a word. Tcl is not Python or C. This means that you've made an array element with the name "pad", including the double quotes. That's legal, but quite unusual in the sort of application you're writing. (The switch you've written looks absolutely fine.) Either you should write:

set p_list(pad) "IO2"

or:

set net_name "\"pad\""

I'm guessing that the former is the one you want.

Possibly also:

set p_list($net_name) "IO2"

And you can change around variable names too.


There are some other options too:

set "p_list(pad)" "IO2"
set net_name {"pad"}

I don't think these are likely to make you happy, but they'll do the right thing.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!