if command error
Closed / Invalid1076248fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 22 years ago
Descriptionplain2004-11-30 20:20:23
Tested on ActiveTcl build8.4.8 and self-built 8.4.8 on
Red hat 9.0
tclsh
% set test_string "</Config>"
</Config>
% if [ regexp "^</(.*)>" $test_string jerk cfg_line ] {
puts $cfg_line
} elseif [ regexp "^<(.*)>" $test_string jerk cfg_line ] {
}
/Config
% if [ regexp "^</(.*)>" $test_string jerk cfg_line ] {
puts $cfg_line
} elseif [ regexp "^<(.*)>" $test_string jerk cfg_line2 ] {
}
Config
%
hobbsplain2004-12-01 07:06:36
Logged In: YES
user_id=72656
Pilot error - you must {} exprs, otherwise they are eval'ed
as expected. In both cases, both regexps are evaled, you
just change the var for the 2nd RE in the 2nd case.
dkfplain2004-12-01 16:09:16
Logged In: YES
user_id=79902
Elaborating on what Jeff said, you probably meant to say this:
if {[ regexp "^</(.*)>" $test_string jerk cfg_line ]} {
puts $cfg_line
} elseif {[ regexp "^<(.*)>" $test_string jerk cfg_line ]} {
}
Notice the {} round the invokations of [regexp]? It's
important (and it also helps the code go faster as a bonus.)
dgpplain2004-12-01 23:41:57
Logged In: YES user_id=80530 The confusion here arises because Tcl was apparently buggy in releases 8.0 through 8.3 on this point, and only in 8.4 did it get corrected. still looking for the relevant bug report.
dgpplain2004-12-01 23:56:50
Logged In: YES user_id=80530 Probably was Bug 219166.
Log in (anonymous is fine) to add a comment.