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 

Manipulating multiple variables simultaneously

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


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Nov 09, 2009 9:12 am    Post subject: Manipulating multiple variables simultaneously Reply with quote

I want to trim multiple variables in a single line of code. For example, trimming the caret symbol (^) from the start and end of the variables a, b, c, d, e, f as below :-

Code:

foreach var {a b c d e f} {set $var [string trim $$var ^]}


The second $ in $$var doesn't get substituted. It behaves as if I had used ${$var}. Is there any 'neat/clever' way to do this without resorting to the following code :-

Code:

foreach var {a b c d e f} {set $var [string trim $[subst -nocommands -nobackslashes $var] ^]}


The problem being any dollar symbol in any one of more of the variable values will probably break the code.
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Mon Nov 09, 2009 9:59 am    Post subject: use set Reply with quote

Code:
set $var [string trim [set $var] ^]

_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Nov 09, 2009 10:28 am    Post subject: Reply with quote

Thanks!

Though I feel a bit of a fool not managing to work that one out myself.
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Nov 09, 2009 12:42 pm    Post subject: Reply with quote

I suppose you could use upvar for this, but otherwize user's suggestion should do just well...
_________________
NML_375, idling at #eggdrop@IrcNET
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