2016-01-15 181 views
2

幾個問題:爲變量賦值給一個函數

  1. 我可以指定一個變量(regvalue)的函數(read_phy),如下的TCL?

    $regvalue = read_phy $phy 19 
    
  2. 我在Perl程序中有以下行。我試圖找出應該是TCL相當於:

    while((read_phy($phy, 18) >> 15) ne 0) { usleep(10000); }; 
    

read_phy(TCL函數)看起來是這樣的:

proc read_phy {phy register} { 

    $value = exec ./read_phy.pl $phy $register 
    string trim $value; 

    if { $::DEBUG } { 
     puts [format "Read PHY %s register %s = 0x%0.8X" $phy $register $value] 
    } 

    if { $::DEBUG } { 
     puts [format "Read PHY %s register %s = 0x%0.8X" $phy $register $value] 
    } 

    set hex $value 

    return ($value); 
} 
+0

read_phy看起來像什麼(源代碼)?你已經嘗試了什麼? – octopusgrabbus

+0

read_phy(tcl函數)如下所示:proc read_phy {phy register} { \t $ value = exec ./read_phy.pl $ phy $ register \t string trim $ value; 如果{$ :: DEBUG} { 看跌期權[格式 「讀取PHY%S寄存器%S = 0X%0.8X」 $ $ PHY寄存器$值] } 如果{$ :: DEBUG} { 看跌期權[格式「讀PHY%寄存器%s = 0x%0.8X」$ phy $ register $ value] } set hex $ value \t return($ value); } – user3565150

+0

這聽起來像是在問函數式編程問題,函數arities。如果沒有,那麼我不理解你的問題。 – octopusgrabbus

回答

3

1.

set regvalue [read_phy $phy 19] 

2。

while { ([read_phy $phy 18] >> 15) != 0} { after 10 } 

也是第2行read_phy的應該是:

set value [exec ./read_phy.pl $phy $register] 
set value [string trim $value] 

- 串裝飾返回一個新的價值,它不會修改它的輸入值。