Archive

Posts Tagged ‘tcl’

resolved – how to remove whitespaces in expect – tcl language

November 15th, 2012 Comments off

Here's the way to remove whitespaces automatically when using expect/tcl language:

If $line is the string variable that you wanna remove whitespaces, just replace $line with the following in your programs context:

[string trim $line]

That's it, simple, Ehh..

resolved – tcl error list element in quotes followed by “” instead of space while executing tcl

November 13th, 2012 1 comment

Today I met an error on tcl with the following error message:

list element in quotes followed by "\/ovm.info" instead of space
while executing
"llength $line"
(procedure "passchg" line 48)
invoked from within
"passchg $prompt $user $pass $host $spawn_id $SCRIPTFILE $SCRIPTFILENAME $resfile"

After some digging, I found the problem was caused in the following tcl script:

if {[llength $line] == 0 || $first_char == ""} {
continue
}

Analysis:

Here's the info from tcl wiki:

The only "problem" is in developers thinking any string can be treated as a list. There are no bugs in Tcl related to list commands and quoting. The problems are when developers try to use list commands on things that are not lists. Thinking of any string can be a list is misunderstanding Tcl.

Resolution:

To resolve this, we need change [llength $line] == 0 to [llength [split $line]] == 0

if {[llength [split $line]] == 0 || $first_char == ""} {
continue
}

So next time we need  replace $arg with [split $arg] whenever lindex/lrange/llength is used.

PS:

 

Categories: IT Architecture, Programming, SHELL Tags: