| View previous topic :: View next topic |
| Author |
Message |
geek Voice
Joined: 24 Oct 2008 Posts: 37
|
Posted: Fri Jan 01, 2021 10:02 am Post subject: strange behavior from llength |
|
|
I have this very simple piece of code:
| Code: |
proc ldmtest {nick host hand chan arg} {
#
# nel RFC 2812 sezione 2.3.1 vengono specificati i caratteri ammessi nel nickname
#
# oltre a lettere e numeri sono permessi i seguenti: [ ] \ ` _ ^ { | } -
#
set RE {[^a-zA-Z0-9\s\[\]\\`_\^\{\|\}-]}
if { [regexp -all -- $RE $arg] } {
puthelp "PRIVMSG $chan :nickname non trovato"
return
}
set nickname [stripcodes * $arg]
set nickname [string trim $nickname]
#putlog "good until here"
set arguments [llength $nickname]
if { $arguments > 1 } {
puthelp "PRIVMSG $chan :specificare un utente alla volta"
return
} elseif { $arguments == 0 } {
puthelp "PRIVMSG $chan :specificare il nickname"
return
}
if { ![onchan $nickname $chan] } {
puthelp "PRIVMSG $chan :nickname non trovato"
return
}
} |
if input is one of this:
when llength runs, I get "Tcl error: unmatched open brace in list"
I just want to count the number of elements... how to get around the problem? |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Fri Jan 01, 2021 10:29 am Post subject: |
|
|
Your arg var is not a list.
Don't use list commands on strings.
Use split to turn arg into a list before checking it for llength.
| Code: |
set nickname [string trim $nickname]
set arguments [llength [split $nickname]]
|
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Last edited by SpiKe^^ on Fri Jan 01, 2021 11:43 am; edited 1 time in total |
|
| Back to top |
|
 |
geek Voice
Joined: 24 Oct 2008 Posts: 37
|
Posted: Fri Jan 01, 2021 11:36 am Post subject: |
|
|
perfect SpiKe^^
very thanks  |
|
| Back to top |
|
 |
|