The join Command

The join command is the inverse of split. It takes a list value and reformats it with specified characters separating the list elements. In doing so, it removes any curly braces from the string representation of the list that are used to group the top-level elements. For example:

join {1 {2 3} {4 5 6}}:
=> 1:2 3:4 5 6 
					

If the treatment of braces is puzzling, remember that the first value is parsed into a list. The braces around element values disappear in the process. Example 5-9 shows a way to implement join in a Tcl procedure, which may help to understand the process:

Example 5-9 Implementing join in Tcl.
proc join {list sep} {
   set s {}   ;# s is the current separator
   set result {}
   foreach x $list {
      append result $s $x
      set s $sep
   }
   return $result
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.100.20