I have the following set of code
lappend to_be_sorted_list {\\\\ABCD 3} {EFG 7} {XYZ 4}
set sorted_list [lsort -decreasing -command -integer inst_length_compare $to_be_sorted_list]
foreach elt $sorted_list {
puts $elt
}
proc inst_length_compare {a b} {
set alength [lindex $a [expr {[llength $a] - 1}]]
set blength [lindex $b [expr {[llength $b] - 1}]]
set diff [expr {$alength - $blength}]
return $diff
}
The output of this proc is
EFG 7
XYZ 4
\\ABCD 3
As you can see 2 of the backslaches in the element "ABCD" disappears in the sorted list. I guess this is probably because '\' is treated as an escape character and lsort removes it. Is there any way to avoid this and have all the 4 backslashes for my "ABCD" element in my sorted list.
lappend to_be_sorted_list {\\\\ABCD 3} {EFG 7} {XYZ 4}
set sorted_list [lsort -decreasing -command -integer inst_length_compare $to_be_sorted_list]
foreach elt $sorted_list {
puts $elt
}
proc inst_length_compare {a b} {
set alength [lindex $a [expr {[llength $a] - 1}]]
set blength [lindex $b [expr {[llength $b] - 1}]]
set diff [expr {$alength - $blength}]
return $diff
}
The output of this proc is
EFG 7
XYZ 4
\\ABCD 3
As you can see 2 of the backslaches in the element "ABCD" disappears in the sorted list. I guess this is probably because '\' is treated as an escape character and lsort removes it. Is there any way to avoid this and have all the 4 backslashes for my "ABCD" element in my sorted list.