See my following test:
```
werner@X10DAi-00:~$ tclsh
tclsh8.6 [~] set a x
x
tclsh8.6 [~] set b y
y
tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
%s" $a $b]x
y
```
As you can see, there is a leading space in the last output line. I want to get multi-line output for a very long variable list, with "\" as a continuation of the code logic row, and align the results.
Any hints on this question?
Regards,
HZ
%s" $a $b]x
Am 24.02.2022 um 08:06 schrieb Harald Oehlmann:
Am 24.02.2022 um 08:00 schrieb Hongyi Zhao:
See my following test:A line continuation with "\" inserts implicitly a space:
```
werner@X10DAi-00:~$ tclsh
tclsh8.6 [~] set a x
x
tclsh8.6 [~] set b y
y
tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
%s" $a $b]x
y
```
As you can see, there is a leading space in the last output line. I
want to get multi-line output for a very long variable list, with "\"
as a continuation of the code logic row, and align the results.
Any hints on this question?
Regards,
HZ
% puts "a\
b"
a b
I hope hit the nail.Sorry:
I hope I hit the nail.
The name of your computer is related to Christian Werner, Mr. Androwish?
Am 24.02.2022 um 08:00 schrieb Hongyi Zhao:Sorry:
See my following test:A line continuation with "\" inserts implicitly a space:
```
werner@X10DAi-00:~$ tclsh
tclsh8.6 [~] set a x
x
tclsh8.6 [~] set b y
y
tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
%s" $a $b]x
y
```
As you can see, there is a leading space in the last output line. I
want to get multi-line output for a very long variable list, with "\"
as a continuation of the code logic row, and align the results.
Any hints on this question?
Regards,
HZ
% puts "a\
b"
a b
I hope hit the nail.
Am 24.02.2022 um 08:00 schrieb Hongyi Zhao:
See my following test:
```
werner@X10DAi-00:~$ tclsh
tclsh8.6 [~] set a x
x
tclsh8.6 [~] set b y
y
tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
%s" $a $b]x
y
```
As you can see, there is a leading space in the last output line. I want to get multi-line output for a very long variable list, with "\" as a continuation of the code logic row, and align the results.
Any hints on this question?
Regards,
HZ
A line continuation with "\" inserts implicitly a space:
% puts "a\
b"
a b
On Thursday, February 24, 2022 at 3:06:11 PM UTC+8, Harald Oehlmann wrote:
A line continuation with "\" inserts implicitly a space:
% puts "a\
b"
a b
Then how to avoid this behavior for a long line cont'd with it?
On Thursday, February 24, 2022 at 3:17:31 PM UTC+8, Harald Oehlmann wrote:
Am 24.02.2022 um 08:06 schrieb Harald Oehlmann:
Am 24.02.2022 um 08:00 schrieb Hongyi Zhao:Sorry:
See my following test:A line continuation with "\" inserts implicitly a space:
```
werner@X10DAi-00:~$ tclsh
tclsh8.6 [~] set a x
x
tclsh8.6 [~] set b y
y
tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
%s" $a $b]x
y
```
As you can see, there is a leading space in the last output line. I
want to get multi-line output for a very long variable list, with "\"
as a continuation of the code logic row, and align the results.
Any hints on this question?
Regards,
HZ
% puts "a\
b"
a b
I hope hit the nail.
I hope I hit the nail.
The name of your computer is related to Christian Werner, Mr. Androwish?
No, it comes from the name of "Werner Lemberg" [1], who inspired me into the world of Tex many years ago.
BTW, who is "Christian Werner, Mr. Androwish"?
[1] https://www.ctan.org/author/lemberg
HZ
Am 24.02.22 um 08:33 schrieb Hongyi Zhao:
On Thursday, February 24, 2022 at 3:06:11 PM UTC+8, Harald Oehlmann wrote:
A line continuation with "\" inserts implicitly a space:
% puts "a\
b"
a b
Then how to avoid this behavior for a long line cont'd with it?You can't for line continuation, but for the problem of formatting some multi-line string there are different solutions.
One is: Create a list instead with one elemnt for each line, then join
with \n:
set l [list "line 1 $a" \
"line 2 $b" \
"line 3"]
# you can break the lines if you wish, but you can also put it on one line
set l [list "line 1 $a" "line 2 $b" "line 3"]
puts [join $l "\n"]
Or you can use "string map" and substitute placeholders in a template
like this:
set template {line 1 @A@
line 2 @B@
line 3 AB @A@@B@}
set vars [list @A@ $a @B@ $b]
puts [string map $vars $template]
The @A@ thing here is not special syntax, it is just any arbitrary
string that does not appear anywhere else in the template.
Or you could use subst, however, that substitutes all Tcl variables:
set template {line 1 $a
line 2 $b
line 3 AB $a$b}
puts [subst -nocommands $template]
The -nocommands prevents subst from substituting bracketed commands in
the template. It's the most simple, but you might reconsider if it is a security risk - depends on the use case.
Christian
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 297 |
Nodes: | 16 (2 / 14) |
Uptime: | 31:03:57 |
Calls: | 6,669 |
Calls today: | 1 |
Files: | 12,216 |
Messages: | 5,338,148 |