I am trying to create an output format like keyword start_number last_number on a dictionary or array format. In my code, I used a dictionary, and the code is:
set keyword_numbers {}
set previous_keyword ""
set last_no 0
foreach item $data {
regexp {(\w+)\[(\d+)\]} $item -> keyword number
set new_keyword "$keyword $number"
puts $keyword
set key_start_end_data [dict create ]
if {$keyword == $previous_keyword} {
if { $number > $last_no } {
set last_no $number
} else {
set last_no $number
}
dict lappend key_start_end_data $keyword_data bit_end $last_no
} else {
set new_keyword $keyword
set start_no $number
set keyword_data [lindex $new_keyword 1]
dict lappend key_start_end_data $keyword_data bit_start $start_no
}
puts $key_start_end_data
set previous_keyword $keyword
}
where the input is, or $data consist
BITS_CLK2QDLY[0]
BITS_CLK2QDLY[1]
BITS_DCC_MAIN[0]
BITS_DCC_MAIN[1]
BITS_DCC_MAIN[2]
BITS_DCC_MAIN[3]
BITS_DCC_MAIN[4]
BITS_DCC_MAIN[5]
BITS_DCC_MAIN[6]
BITS_FIXDLY_MAIN[0]
BITS_FIXDLY_MAIN[1]
BITS_FIXDLY_MAIN[2]
BITS_FIXDLY_MAIN[3]
BITS_FIXDLY_MAIN[4]
BITS_FIXDLY_MAIN[5]
BITS_FIXDLY_MAIN[6]
BITS_FIXDLY_MAIN[7]
BITS_NDE_DLY[0]
BITS_NDE_DLY[1]
BITS_NDE_DLY[2]
BITS_NDE_DLY[3]
BITS_NDE_DLY[4]
BITS_NDE_DLY[5]
BITS_NDE_DLY[6]
BITS_NDE_DLY[7]
the expected output is In dictionary
BITS_DCC_MAIN { bit_end: 0 bit_start: 6 }
BITS_FIXDLY_MAIN { bit_end: 0 bit_start: 7 }
BITS_NDE_DLY{ bit_end: 0 bit_start: 7 }
or in array
BITS_CLK2QDLY [ 0 1 ]
BITS_DCC_MAIN [ 0 6 ]
BITS_FIXDLY_MAIN [0 7 ]
BITS_NDE_DLY[ 0 7 ]
this is what i am getting
{} {bit_start 0}
{} {bit_end 1}
{} {bit_start 0}
{} {bit_end 1}
{} {bit_end 2}
{} {bit_end 3}
{} {bit_end 4}
{} {bit_end 5}
{} {bit_end 6}
{} {bit_start 0}
{} {bit_end 1}
{} {bit_end 2}
{} {bit_end 3}
{} {bit_end 4}
{} {bit_end 5}
{} {bit_end 6}
{} {bit_end 7}
{} {bit_start 0}
{} {bit_end 1}
{} {bit_end 2}
{} {bit_end 3}
{} {bit_end 4}
{} {bit_end 5}
{} {bit_end 6}
{} {bit_end 7}
Can anyone tell me what wrong with this code? Please mention any doubts related to my question or clarification in the comment section.