Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda