Cecil Westerhof <
Ce...@decebal.nl> wrote:
> At the moment I have the following function:
> proc getHourInDay {{currentTime -1}} {
> if {${currentTime} == -1} {
> set currentTime [clock seconds]
> }
> scan [clock format ${currentTime} -format %H] %d
> }
>
> But I would like to do something like:
> proc getHourInDay {{currentTime [clock seconds]}} {
> scan [clock format ${currentTime} -format %H] %d
> }
> ...
>
> Do I have to do it like the first code, or is there a better way?
I don't know if it is _better_, but there is _a way_ to create
something that works like you appear to expect the second version to
work.
proc getHourInDay {{currentTime {[clock seconds]}}} {
scan [clock format [subst $currentTime] -format %H] %d
}
But, note, this works only because the expected input to the proc is
usually an integer. For proc's that take strings that might contain
command substitutions ([]'s) it likely won't work as expected, and
potentially could open up something like an sql-injection attack if the
input string were externally user controllable. I.e, think about what
would happen if a user could get a string of the form "[exec format
c:]" (or something similarly dangerous) to be passed to the proc.