by greenpeas · 3y ago · 0 comments
#!/usr/bin/env tclsh
puts $argv
I kinda wanted to stop reading after this example. It feels dishonest to start with an example for which there is a builtin. Why didn't you show instead how to output arguments joined by a comma or some other separator instead of space.
If I were to update the Go or Python examples to use another separator, it'd be just a 1-2 character change, whereas for Tcl I have no idea how that would look.The Tcl variant to output "comma" as separator (note -- this is not "CSV").
puts [join $argv ,]
If you wanted "comma space" you'd do: puts [join $argv ", "]
If you actually wanted "CSV" then it would be (assuming tcllib is installed): package require csv
puts [csv::join $argv] puts [join $argv]
to avoid that little issue. Doing "puts $argv" triggers Tcl's output of "lists" in a special format that allows the list to be parsed from the text again at a later time.