Artifacts Associated With Ticket 1490503
Ticket change [dbbf977409] (rid 108014) by sachulka on 2006-05-17 20:30:07:
- assignee initialized to: "dkf"
- cmimetype initialized to: "text/plain"
- comment initialized to:
I recently upgraded from Tcl8.3 to Tcl8.4.13 on solaris and discovered this difference which does not seem right. here is my little program: proc send_user { x } { puts $x } set alarmRecord [list "abc: def" "ALARM 1: blah" "ghi: jkl" "ALARM 2: fjdasl"] foreach record $alarmRecord { if [regexp {(ALARM)[^:]+([0-9]+)} $record match key value] { send_user ">KEY $key VALUE $value\n" } elseif [regexp {([^:]+):(.*)} $record match key value] { send_user "KEY2 $key VALUE $value\n" } } Here are the results, the key and value are different for different Tcl versions: sapphire:~/thuyscripts {ewuthle_eusbd00250}> tclsh8.3 KEY2 abc VALUE def >KEY ALARM VALUE 1 KEY2 ghi VALUE jkl >KEY ALARM VALUE 2 sapphire:~/thuyscripts {ewuthle_eusbd00250}> tclsh % info tclversion 8.4 KEY2 abc VALUE def >KEY ALARM 1 VALUE blah KEY2 ghi VALUE jkl >KEY ALARM 2 VALUE fjdasl So if regexp is in the foreach loop and the same variables (key/value) are used inside if - regexp does not match correctly. - foundin initialized to: "obsolete: 8.4.13"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "sachulka"
- subsystem initialized to: "16. Commands A-H"
- title initialized to: "regexp within foreach loop matches wrong"
- type initialized to: "Bug"
Ticket change [86e42145a1] (rid 131594) by msofer on 2006-05-18 03:59:37:
- assignee changed to: "msofer"
- closedate changed to: "2006-05-17T20:59:37"
- closer changed to: "msofer"
- icomment:
Logged In: YES user_id=148712 The bug is actually in Tcl8.3 (although I did not confirm the behaviour there), the behaviour in 8.4 is correct. Your script is missing some braces in order to perform according to your expectation: it should be if {[regexp ...]} { send_user ">KEY $key VALUE $value\n" } elseif {[regexp ...] { send_user "KEY2 $key VALUE $value\n" } Please note that the conditions to 'if ... elseif' are enclosed in braces. This means that they are passed to 'if' as strings; when 'if' evals the first condition and finds it is true, it never evaluates the second. In your script as posted, both regexp's are evaluated *before* they are passed as arguments to 'if'; so, even when the first regexp matches, the values $key and $value are set by the second regexp. - login: "msofer"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Closed"
- username: "msofer"
Ticket change [edd7e54bea] (rid 103969) by nobody on 2006-05-18 14:57:49:
- icomment:
Logged In: NO See also bug 219166, it was fixed in 8.4a4
- login: "nobody"
- mimetype: "text/plain"
- username: "nobody"
- icomment:
Ticket change [ed10dfe592] (rid 103817) by dkf on 2006-05-18 15:06:22:
- subsystem changed to: "47. Bytecode Compiler"