Sujet : Re: misunderstaning of switch command
De : wortkarg3 (at) *nospam* yahoo.com (Harald Oehlmann)
Groupes : comp.lang.tclDate : 24. Jun 2025, 13:06:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <103e4bl$20g3f$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
Am 24.06.2025 um 12:53 schrieb Schelte:
On 24/06/2025 10:23, Mark Summerfield wrote:
I have a switch command which is doing something I don't expect but I
don't understand what I've done wrong. In this example the default is
always executed but I expect the case before that to be executed.
>
const UNCOMPRESSED U
const ZLIB_COMPRESSED Z
const SAME_AS_PREV =
set filename somefile.txt
set action "added"
set kind Z
switch $kind {
$::SAME_AS_PREV { puts "unchanged \"$filename\"" }
$::UNCOMPRESSED { puts "$action \"$filename\"" }
$::ZLIB_COMPRESSED { puts "$action \"$filename\" (zlib
compressed)" }
default { puts "!!!!!!!! UNEXPECTED !!!!!!!!" }
}
>
What am I doing wrong?
Switch allows for two different ways to specify the pattern/body pairs: As as a single argument or as individual arguments. If you want the patterns to be in variables (or consts) you may prefer the latter method. This can be written as:
switch $kind \
$::SAME_AS_PREV {
puts "unchanged \"$filename\""
} $::UNCOMPRESSED {
puts "$action \"$filename\""
} $::ZLIB_COMPRESSED {
puts "$action \"$filename\" (zlib compressed)"
} default {
puts "!!!!!!!! UNEXPECTED !!!!!!!!"
}
Schelte.
RIGHT YOU ARE !