Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda