Getting an error in Tcl script as No Variable declared

set pwr_rpt [split [report_power -quiet -return_string -xpe ${pd}_${rd}.xpe] \n]
for {set i 0} {$i<150} {incr i} {
    set line [clean_line [lindex $pwr_rpt $i]]
    if {[lrange $line 1 4] == "Total On-Chip Power W"} {
        puts total_power [lindex $line 6]; # Am getting an error here as variable not declared 
        set total_power [lindex $line 6]
    }
}

Getting error as no variable declared

Upvotes: 0

Views: 156

Answers (2)

Kevan Riley
Kevan Riley

Reputation: 36

I think you need quotes on your "puts" command:

set pwr_rpt [split [report_power -quiet -return_string -xpe ${pd}_${rd}.xpe] \n]
for {set i 0} {$i<150} {incr i} {
    set line [clean_line [lindex $pwr_rpt $i]]
    if {[lrange $line 1 4] == "Total On-Chip Power W"} {
        puts "total_power [lindex $line 6]" ; # Quotes here
        set total_power [lindex $line 6]
    }
}

Upvotes: 0

Chris Heithoff
Chris Heithoff

Reputation: 1863

Your error is probably not "no variable declared" but is probably "can not find channel named 'total_power'"

You're using the puts commands with two arguments.

puts total_power [lindex $line 6]

where total_power is the first argument and [lindex $line 6] is the second argument.

When used with two arguments, the first argument must be an open channel and the second argument is the string to write to the open channel. You don't have an open channel named "total_power".

You need to simply group these together with double quotes:

puts "total_power [lindex $line 6]"

Upvotes: 2

Related Questions