Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: b1afffd69ab55bf90fb987409817d787d16558c2
Ticket: 1537233fffffffffffffffffffffffffffffffff
Switch doesn't variable substitution
User & Date: ctasada on 2006-08-09 08:57:41
Changes

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    Hi again guys,
    
    I've seen a feature request that can be related
    (1106138) so probably it's a known "feature" of the
    switch command.
    
    Anyway I find it quite strange.
    
    Here is the script that shows the actual problem:
    # Create some variables and assign numbers to them
    set one 1
    set two 2
    set three 3
    set value 2
    
    switch -- $value {
    $one {puts 1}
    $two {puts 2}
    $three {puts 3}
    default {puts "$value is unknown"}
    }
    % 2 is unknown
    
    switch -- $value {
    1 {puts 1}
    2 {puts 2}
    3 {puts 3}
    default {puts "$value is unknown"}
    }
    % 2
    
    As you can see looks like is not doing the variable
    substitution. Googling a bit I found this solution:
    
    switch -- $value [list\
    $one {puts 1}\
    $two {puts 2}\
    $three {puts 3}\
    default {puts "$value is unknown"}\
    ]
    % 2
    
    Which works, but is quite dirty.
    
    Should be considered a bug?
    
  4. foundin changed to: "obsolete: 8.5a4"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "ctasada"
  10. subsystem changed to: "18. Commands M-Z"
  11. title changed to: "Switch doesn't variable substitution"
  12. type changed to: "Bug"