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.

problem with split

Old posts that have not been replied to for several years.
Locked
e
eiSi
Halfop
Posts: 70
Joined: Thu Mar 07, 2002 8:00 pm

problem with split

Post by eiSi »

hi there!

this is my little proc:

proc qrequest {nick uhost hand chan args} {
global qqueue home
set commands [split $args " "]
set channel [lindex $commands 0]
set chantype [lindex $commands 1]
lappend qqueue $channel
lappend qqueue $nick
lappend qqueue $chantype
set qqlength [expr [llength $qqueue] / 3]
notice $nick "$nick, your request for $channel (Type: $chantype) has been queued. There are $qqlength items in queue."
}

but the response I get:

tuxX, your request for {#rbot (Type: private}) has been queued. There are 1 items in queue.

why are there those {} brackets?

thanks for any help!
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

This is because fo the way you split it, and the variable name you used.

$args has a special function in Tcl, and is used to access unlimited length argument lists. Examples of this include the "list" command, where can keep on specifying items to add.

The $args vaiable is allready a list of the arguments passed, so you don't need to split it.

Change this to arg in the definition, and the same in the split.

Second, you dont need the " " in the split. Split uses " " by default.

That should be enough to fix the script for you.
e
eiSi
Halfop
Posts: 70
Joined: Thu Mar 07, 2002 8:00 pm

Post by eiSi »

ah thanks!

I didn't know that.

But now all works fine :)

Thanks again! :)
b
bz

Post by bz »

The '{' and '}' are used to define the start and end of a list(object).

I think ur problem occurs because u use the variable name 'args' which already creates a list from the rest of the input string. Try this:

Code: Select all

proc qrequest {nick uhost hand chan arg} { 
  global qqueue home 
  set commands [split $arg]  
  lappend qqueue [lindex $commands 0]
  lappend qqueue $nick 
  lappend qqueue [lindex $commands 1]
  set qqlength [expr [llength $qqueue] / 3] 
  notice $nick "$nick, your request for $channel \(Type: $chantype\) has   been queued. There are $qqlength items in queue." 
} 

Last edited by bz on Thu Apr 10, 2003 6:54 am, edited 1 time in total.
b
bz

Post by bz »

ok ignore my reply .. :roll:
e
eiSi
Halfop
Posts: 70
Joined: Thu Mar 07, 2002 8:00 pm

Post by eiSi »

hehe but thank you anyway! :)
Locked