Tcl Source Code

View Ticket
Login
Ticket UUID: 2032614
Title: Missleading "switch" example
Type: Bug Created on: 2008-07-30 11:35:00
Submitter: nobody Assigned to: davidw
Subsystem: 75. Tutorial Severity:
Priority: 5 Medium Last modified: 2008-07-30 11:35:00
Status: Open Closed by:
Resolution: None Closed on:
Version: None
Description:
The first example at http://www.tcl.tk/man/tcl8.5/tutorial/Tcl8.html is missleading. I've build a similar case and got an unexpected result:

set align 2;
set center 2;
set right 3;

switch $align {
  $center {
    set align "center"; 
  } 
  $right {
    set align "right";
  } 
  default { 
    set align "left"; 
  }
}

dump $align;

I expected to get "center" but I got "left". When modifying the example a bit to this it works as expected:

set align 3;
set center 2;
set right 3;

switch $align $center {
  set align "center"; 
} $right {
 set align "right";
} default { 
  set align "left"; 
}

dump $align;

Main irritation for me as a TLC beginner was the use of variables inside the opening braket "{" which does not work and the newline after a closing braket for each case.