soymanue
Oct 12, 2012Nimbostratus
Hostname split
Hello
I need to split a hostname into three parts ( ..).
This can be done al least on two ways:
1) scan [HTTP::host] %\[^.\].%\[^.\].%s prefix host suffix
2) set prefix [getfield [HTTP::host] "." 1]
set host [getfield [HTTP::host] "." 2]
set suffix [getfield [HTTP::host] "." 3]
Both work, but the problem comes when there is no prefix ( f5.com instead of www.f5.com). In that case scan fails and the second method leaves suffix empy, assign .com to host and f5 to prefix
I've done this to solve this:
set longitud [ string length $suffix ]
if { $longitud < 1 } {
set host [string tolower $prefix ]
}
It works, but it doesn't look quite ellegant nor efficient.
Is there a better way to solve that particular case?
Thank you.