egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

strange behavior from llength

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
geek
Voice


Joined: 24 Oct 2008
Posts: 37

PostPosted: Fri Jan 01, 2021 10:02 am    Post subject: strange behavior from llength Reply with quote

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:
    {
    {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?
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Fri Jan 01, 2021 10:29 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
geek
Voice


Joined: 24 Oct 2008
Posts: 37

PostPosted: Fri Jan 01, 2021 11:36 am    Post subject: Reply with quote

perfect SpiKe^^

very thanks Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber