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.

set args [split $args]

Old posts that have not been replied to for several years.
Locked
x
xces

set args [split $args]

Post by xces »

I have a msg bind. I want the user to do be able to use:

!invite user pass

Code:
set args [split $args]
set usr [lindex $args 0]
set pwd [lindex $args 1]

So i do:
!invite xces test

I get:
$usr = "{xces"
$pwd = "test}"

But i don't need the { and }... how do remove those?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Do not use $args in the first place.

They have a special meaning in Tcl. Allow you to use unlumited length argument lists for procedures.

Simply changing any occurance of $args to $arg will normaly cure 99% of problems.
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Re: set args [split $args]

Post by egghead »

xces wrote:I have a msg bind. I want the user to do be able to use:

!invite user pass

Code:
set args [split $args]
set usr [lindex $args 0]
set pwd [lindex $args 1]

So i do:
!invite xces test

I get:
$usr = "{xces"
$pwd = "test}"

But i don't need the { and }... how do remove those?
It is because of the special meaning of the word "args". (This question could be added to the FAQ on this forum).

If you have a proc that you want to call with a variable number of arguments, you can use the special reserved word "args".

Code: Select all

# Proc definition using keywords "args"

proc myproc { args } {
   set arg0 [lindex $args 0]
   set arg1 [lindex $args 1]
   ...
   ...
}

# call the proc with one argument

myproc foo

# call the proc with two arguments

myproc foo bar

In your particular case, there is only one argument: the string of text "xces test". To pass this string of text as a list (with one element) to your proc, Tcl embraces it. Thus you get: {xces test}. Then you apply a split command to it, with the result you have shown.

Easiest solution: Do not use the keyword "args", but use something different like "text" or "pubstring".

You can use "args" but then you must treat it as a list having one element: the line of text entered on the channel.
x
xces

Post by xces »

Cool thanx for the replys, gonna test it tomorrow :D Now it is time for bed, it's 06:04 here, just finished working @ a local club... :D
Locked