Reputation: 16428
When I am chasing my work with Tcl
code, surprised by the below code's output.
#!/usr/bin/tclsh
puts [split {a:b:c:d} :]
puts [split {a;b;c;d} ;]
puts [split {a-b-c-d} -]
puts [split {a b c d} ]; # 'space' will be taken as split-char here.
Output:
a b c d
{a;b;c;d;}
a b c d
a b c d
As you can see, {a;b;c;d;}
is a list with one element.
With semi-colon as the separator character, split
is returning the whole input as one single element-ed list instead of providing each word as each element for that list.
Upvotes: 1
Views: 1444
Reputation: 5723
A semicolon is also an optional statement end indicator.
Try:
puts [split {a;b;c;d} {;}]
I'm wondering why it didn't give a syntax error though.
Upvotes: 3