how to create tcl proc with hyphen flag arguments

后端 未结 4 791
面向向阳花
面向向阳花 2020-12-10 22:06

Im searching all over the internet , i guess im searching not the right keywords i tried most of them :)

i want to create in tcl/bash a proc with hyphen flags to get

4条回答
  •  半阙折子戏
    2020-12-10 22:18

    With array set, we can assign the parameters and their values into an array.

    proc getInfo {args} {
        # Assigning key-value pair into array
        # If odd number of arguments passed, then it should throw error
        if {[catch {array set aInfo $args} msg]} {
            return $msg
        }
        parray aInfo; # Just printing for your info
    }
    
    
    puts [getInfo -name Dinesh -age 25 -id 974155]
    

    will produce the following output

    aInfo(-age)  = 25
    aInfo(-id)   = 974155
    aInfo(-name) = Dinesh
    

提交回复
热议问题