| View previous topic :: View next topic |
| Author |
Message |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Mon Nov 09, 2009 9:12 am Post subject: Manipulating multiple variables simultaneously |
|
|
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 |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Mon Nov 09, 2009 9:59 am Post subject: use set |
|
|
| Code: | | set $var [string trim [set $var] ^] |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Mon Nov 09, 2009 10:28 am Post subject: |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon Nov 09, 2009 12:42 pm Post subject: |
|
|
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 |
|
 |
|