This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

expr double issue

Help for those learning Tcl or writing their own scripts.
Post Reply
t
tonyrayo
Voice
Posts: 20
Joined: Thu Jul 31, 2003 3:29 pm
Location: Waldorf, MD
Contact:

expr double issue

Post by tonyrayo »

Hi guys, I am trying to help a friend debug a script. I have only started learning tcl and haven't gotten to math functions yet. The question would be best stated in the code that's being used.

First is the code that retrieves the info for us...

Code: Select all

if {[catch {exec cat /proc/cpuinfo | grep "cpu MHz"} cpuspeed]} {set cpuspeed "Unknown"}
Then according to that code it should parse the Mhz command or reply with "Unknown".

Then to parse "cpu MHz : 1596.000" (without the quotes)

Code: Select all

set cpuspeed "[expr double(round([string map {"cpu MHz		: " ""} $cpuspeed]))]"
What is going wrong? Is the mhz not coming back correctly? This is the error code.

Code: Select all

Tcl error [msg_uptime]: syntax error in expression "double(round(1596.000 1596.000))": missing close parenthesis at end of function call
so I assume it has to do with the double command. It worked when used with a 700mhz CPU. The only other code related to cpu further down is this...

Code: Select all

if {$cpuspeed >= 1000} {
		set cpuspeed "[expr $cpuspeed/1000]GHz"
	} else {
		set cpuspeed "[expr round($cpuspeed)]MHz"
I know this is something easy but I am way too tired and sick to figured it out myself or skip ahead in my tcl books and try to fill in the knowledge. Any help would make me much grateful. Thank you.

- Tony R.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Would this be a system with multiple cores or such?
The reason for your error, is that you got two cpu-speeds in that string. Yet, round() only expects one float, and thus starts nagging when it finds something else than a closing ")".

1596.000 is most certainly small enough for tcl to handle, so size should'nt matter
NML_375
Post Reply