proc mulval { addr } {
if {regexp {^([2][2-3][0-9])\.+(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-])\.+(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.+(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$} $addr } {
puts "Valid IP Multicast Address"
} else {
puts"Invalid IP multicast Address"
}
}
The above code generates the error invalid bareword "regexp" in tcl .
I wanna know what is the mistake in the word and what is invalid bareword in tcl.How to debug.
The mistake is that
regexp
is written as an unqualified string inside the first argument toif
. If you want to have the result of a command as an operand in the condition argument you need to put brackets around it:[regexp ...]
.But you shouldn't use regular expressions to validate IP numbers. Dotted decimal is only one of the many possible ways to write an IP number, and trying to sort them out with regular expressions is going to be painful and error-prone.
Use the
ip
module instead. I'm not an IP expert, but the following should work:Documentation for the Tcllib ip module
Documentation: if, package, proc, puts, set