Home > TCL, Technical > TCL Tips

TCL Tips


Note: Credits for the tips mentioned here goes to multiple people
and internet sites.  I just consolidated them together for my reference.

Hex Codes for special key combinations to be send to routers/PC

Refer the following table for the hexa decimal code for each of the special key combinations. Most frequently used one is CTRL+C. This can be used in tcl/expect to send these key combinations to a router/PC.

KeyCombination Hexadecimal
CTRL-@ 0x00
CTRL-A 0x01
CTRL-B 0x02
CTRL-C 0x03
CTRL-D 0x04
CTRL-E 0x05
CTRL-F 0x06
CTRL-G 0x07
CTRL-H 0x08
CTRL-I 0x09
CTRL-J 0x0A
CTRL-K 0x0B
CTRL-L 0x0C
CTRL-M 0x0D
CTRL-N 0x0E
CTRL-O 0x0F
CTRL-P 0x10
CTRL-Q 0x11
CTRL-R 0x12
CTRL-S 0x13
CTRL-T 0x14
CTRL-U 0x15
CTRL-V 0x16
CTRL-W 0x17
CTRL-X 0x18
CTRL-Y 0x19
CTRL-Z 0x1A

Dynamic variables in Tcl (Eval command to the rescue)

Most often I ran in to issue how to reference or retrieve value from a dynamic tcl variable (or value of a variables, variable)..Got confused!!!? let me explain with an example what the problem is and whats the solution?

set vlanid "11 12 13"
set iplst "11.0.0.1 12.0.1 13.0.1"
#Now you want to have the below mapping
#vlan 11->11.0.0.1
#vlan 12->12.0.0.1
#vlan 13->13.0.0.1
#Now lets say i have to store the ip of vlan 11 in a name referenced by the vlan id like below

foreach id $vlanid ip $iplst {
set vlan$id $ip
}

#Now we have the following variable to value mapping
#vlan11 --> 11.0.0.1
#vlan12 --> 12.0.0.1
#vlan13 --> 13.0.0.1
#The above is called dynamic variable as the variable name is dynamically changing

#Now comes the real question, how to get the value of a dynamic variable
#I cannot use puts "$vlan$id" as it will error out saying cannot read "vlan" no such variable.
#This is where the power of eval comes in to picture and below is the solution

foreach i $vlanid {
puts "The ip of vlan $i is [eval set vlan$i]"
}

The above code will give the output

The ip of vlan 11 is 11.0.0.1
The ip of vlan 12 is 12.0.0.1
The ip of vlan 13 is 13.0.0.1

Advertisements
Categories: TCL, Technical
  1. July 22, 2014 at 9:00 AM

    What’s up, yeah this post is actually fastidious and I have learned lot of things from it concerning blogging.
    thanks.

  2. September 10, 2014 at 1:36 AM

    I like the helpful info you provide on your articles.
    I will bookmark your blog and test again here frequently. I’m slightly sure I will be told a lot of new stuff proper right here!

    Good luck for the next!

  3. January 9, 2015 at 7:19 PM

    Remarkable issues here. I’m very satisfied to see your article.
    Thanks so much and I am taking a look forward to contact you.
    Will you kindly drop me a e-mail?

  4. August 4, 2015 at 7:17 PM

    Hi there to every , for the reason that I am truly eager of
    reading this blog’s post to be updated daily.
    It carries good material.

  5. August 6, 2015 at 8:03 PM

    Good information. Lucky me I discovered your blog by
    accident (stumbleupon). I’ve saved as a favorite for later!

  6. August 9, 2015 at 1:52 PM

    Hi! I could have sworn I’ve visited this blog before but after going through
    a few of the posts I realized it’s new to me. Anyways, I’m certainly happy I came
    across it and I’ll be bookmarking it and checking back regularly!

  1. August 8, 2015 at 8:08 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: