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.
Old posts that have not been replied to for several years.
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Mon Mar 29, 2004 12:52 am
i wana rearange a string backwards ex: adcb to bcda how would i do this ? without loozing data.
ive checked lsort but it seems that this command hasn't this option..
XplaiN but think of me as stupid
spock
Master
Posts: 319 Joined: Thu Dec 12, 2002 8:40 pm
Post
by spock » Mon Mar 29, 2004 5:10 am
Code: Select all
proc flipstring { s } {
set newstring ""
set length [string length $s]
while { [string length $newstring] != [string length $s] } {
set newstring "$newstring[string index $s [expr $length - 1]]"
incr length -1
}
return $newstring
}
there are better ways to do this so user, strikelight or ppslim might hit you up
% flip adcb
bcda
% time { flip adcb } 100
1015 microseconds per iteration
maybe some native command does it for you but i assume not since you're asking
photon?
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Mon Mar 29, 2004 6:24 am
This is about 7 times faster than the above (for short strings) in my tclsh:
Code: Select all
proc reverse str {
set out ""
foreach c [split $str ""] {set out $c$out}
set out
}
Have you ever read "The Manual"?
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Mon Mar 29, 2004 10:35 am
TnX nice i am amazed that this doesn't give an error ..
set out
???
XplaiN but think of me as stupid
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Mon Mar 29, 2004 1:49 pm
set varName ?
value ?
Returns the value of variable
varName . If
value is specified, then set the value of
varName to
value ...
Have you ever read "The Manual"?
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Mon Mar 29, 2004 1:57 pm
As in is the same thing as in using "return" instead of "set" ?
Once the game is over, the king and the pawn go back in the same box.
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Mon Mar 29, 2004 2:20 pm
caesar wrote: As in is the same thing as in using "return" instead of "set" ?
Nope...check the '
proc ' manual page.
If the procedure doesn't execute an explicit return, then its return value is the value of the last command executed in the procedure's body.
Have you ever read "The Manual"?
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Mon Mar 29, 2004 2:50 pm
ic interesting .. so in a way ur saying if the variable exists , and u set it again then it returns the last executed string or the last string that was set .. basicly its the same as return but not entirely .. so this wouldn't break a loop and still return a value .. example ..
XplaiN but think of me as stupid
ppslim
Revered One
Posts: 3914 Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England
Post
by ppslim » Tue Mar 30, 2004 6:11 am
Yes. This provides a nice way to access variables dynamicly.
IE
Code: Select all
set ourvar "hello"
set thisvar "ourvar"
puts -stdout [set $thisvar]
Mixed with the fact that Proc declarations will return the buffer of the last executed command, if no exclicit return is performed.
This is the precise reason you have to be careful if you are using RAW binds. Because if no return is used, the buffer from the last command is used. Thus.... you can often lose data because you forgot an explicit return.
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Tue Mar 30, 2004 11:53 am
Heh, nice. Thanks for pointing this out user.
Once the game is over, the king and the pawn go back in the same box.