This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

strange behavior from llength

Help for those learning Tcl or writing their own scripts.
Post Reply
g
geek
Halfop
Posts: 47
Joined: Fri Oct 24, 2008 6:07 am

strange behavior from llength

Post by geek »

I have this very simple piece of code:

Code: Select all

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:
  • {
    {a
    { a
    { {
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?
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

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: Select all

set nickname [string trim $nickname]
set arguments [llength [split $nickname]]
Last edited by SpiKe^^ on Fri Jan 01, 2021 11:43 am, edited 1 time in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
g
geek
Halfop
Posts: 47
Joined: Fri Oct 24, 2008 6:07 am

Post by geek »

perfect SpiKe^^

very thanks :)
Post Reply