On https://www.tcl.tk/man/tcl8.5/TclCmd/format.html I see:
If the % is followed by a decimal number and a $, as in “%2$d”,
then the value to convert is not taken from the next sequential
argument. Instead, it is taken from the argument indicated by the
number, where 1 corresponds to the first arg. If the conversion
specifier requires multiple arguments because of * characters in
the specifier then successive arguments are used, starting with
the argument given by the number. This follows the XPG3
conventions for positional specifiers. If there are any positional
specifiers in formatString then all of the specifiers must be
positional.
So I wrote:
puts [format "ERROR:\
%1$s \
%1$s -once \
%1$s -Tk" [file tail ${::argv0}]]
But this gives:
can't read "s": no such variable
while executing
"format "ERROR: %1$s %1$s -once %1$s -Tk"
[file tail ${::argv0}]"
Am I doing something wrong, or is the documentation incorrect?
On https://www.tcl.tk/man/tcl8.5/TclCmd/format.html I see:
If the % is followed by a decimal number and a $, as in ?%2$d?,
then the value to convert is not taken from the next sequential
argument. Instead, it is taken from the argument indicated by the
number, where 1 corresponds to the first arg. If the conversion
specifier requires multiple arguments because of * characters in
the specifier then successive arguments are used, starting with
the argument given by the number. This follows the XPG3
conventions for positional specifiers. If there are any positional
specifiers in formatString then all of the specifiers must be
positional.
So I wrote:
puts [format "ERROR:\
%1$s \
%1$s -once \
%1$s -Tk" [file tail ${::argv0}]]
But this gives:
can't read "s": no such variable
while executing
"format "ERROR: %1$s %1$s -once %1$s -Tk" [file tail ${::argv0}]"
Am I doing something wrong, or is the documentation incorrect?
In article <[email protected]>,
Cecil Westerhof <[email protected]> wrote:
On https://www.tcl.tk/man/tcl8.5/TclCmd/format.html I see:
If the % is followed by a decimal number and a $, as in “%2$dâ€, >> then the value to convert is not taken from the next sequential
argument. Instead, it is taken from the argument indicated by the
number, where 1 corresponds to the first arg. If the conversion
specifier requires multiple arguments because of * characters in
the specifier then successive arguments are used, starting with
the argument given by the number. This follows the XPG3
conventions for positional specifiers. If there are any positional
specifiers in formatString then all of the specifiers must be
positional.
So I wrote:
puts [format "ERROR:\
%1$s \
%1$s -once \
%1$s -Tk" [file tail ${::argv0}]]
But this gives:
can't read "s": no such variable
while executing
"format "ERROR: %1$s %1$s -once %1$s -Tk" >>[file tail ${::argv0}]"
Am I doing something wrong, or is the documentation incorrect?
Shouldn't you be curly bracing your format string instead of
double quoting so Tcl doesn't try to do variable expansion on it?
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 03:55:15 |
| Calls: | 12,099 |
| Calls today: | 7 |
| Files: | 15,003 |
| Messages: | 6,517,888 |