0

i have an if loop loop where i configure commands in router as

    mode contains config or unconfig as values

if {[regexp -nocase {^config$} $mode]} {

set conf ""

} else {

 set conf no

}

 $router config "$conf primary command\n"

 $router config "$conf secondary command\n"

when mode is set to config everthing is fine , primary command is configured first and then secondary command" but while unconfiguring i want secondary command to executed first and then only it allows me to remove primary command...so when $mode changes will i be able to swap the order of execution?

4

3 に答える 3

1

ユーザーがすぐに実行するのではなく、実際に何らかのシグナルで操作を実行するだけで、コードに操作のリストを保持させて実行することができます。次に、実行順序を交換することは、リストを逆方向に処理することです。これは非常に簡単です (そしてlreverse役立つかもしれません)。

私は個人的にそれをする傾向はありません。通常の Tcl の方法は、指定された順序ですぐに実行することです。これに対する唯一の注目すべき例外は、Tk (表示とレイアウトを「アイドル状態になるまで」、つまり、保留中のイベントがない場合に延期する) と、いくつかの用途での Expect (これは部分的です。expect一度に多くのことを行うことができますが、それらはチェックされます) です。指定された順序で)。

于 2013-01-29T15:23:34.603 に答える
0

そんな感じ?

if {$conf == "no"} {
    $router config "$conf primary command\n"
    $router config "$conf secondary command\n"
} else {
    $router config "$conf secondary command\n"
    $router config "$conf primary command\n"
}
于 2013-01-29T14:30:02.743 に答える
0
proc myConf {cmd} {
  global myConfs router

  $router config "$cmd\n"
  lappend myConfs $cmd
}

# configure
set myConfs {}
myConf "primary command"
myConf "secondary command"

# unconfigure
foreach cmd [lreverse $myConfs] {
  $router config "no $cmd\n"
}
于 2013-01-29T16:52:12.407 に答える