TCL get array value using variable as key name -


i have following array list contains iana cipher suites ids (key name) corresponding names (values)

array set iana_ciphers [list {0000} {"tls_null_with_null_null"} \         {0001} {"tls_rsa_with_null_md5"} \         {0002} {"tls_rsa_with_null_sha"} \         {0003} {"tls_rsa_export_with_rc4_40_md5"} \         [...]         {c0af} {"tls_ecdhe_ecdsa_with_aes_256_ccm_8"} ] 

now need able access array's values dynamically when use following code error "can't read "iana_ciphers(0000)": no such element in array"

set ciphers "000000010002" set tmp [string range $ciphers 0 3] ;# gives "0000" puts $iana_ciphers($tmp) ;# throws error 

what doing wrong ?

thanks , regards

you should set variable

set ciphers "000000010002" 

update 2

i don't know whether additional braces in array set command typo or not.

array set iana_ciphers [list {0000} {"tls_null_with_null_null"} \         {0001} {"tls_rsa_with_null_md5"} \         {0002} {"tls_rsa_with_null_sha"} \         {0003} {"tls_rsa_export_with_rc4_40_md5"} \         [...]         {c0af} {"tls_ecdhe_ecdsa_with_aes_256_ccm_8"} ] } # '}' not needed @ all. 

you should getting error as

-------- invalid command name "}"     while executing "}" 

by way, without that, have tried code , working fine me.

array set iana_ciphers [list {0000} {"tls_null_with_null_null"} \         {0001} {"tls_rsa_with_null_md5"} \         {0002} {"tls_rsa_with_null_sha"} \         {0003} {"tls_rsa_export_with_rc4_40_md5"} \         {c0af} {"tls_ecdhe_ecdsa_with_aes_256_ccm_8"} ]  set ciphers "000000010002" set tmp [string range $ciphers 0 3] ;# gives "0000" puts "key : $tmp" puts "value : $iana_ciphers($tmp)"  

output :

key : 0000 value : "tls_null_with_null_null" 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -