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 

"Tip of the day"
Goto page Previous  1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Tcl FAQ
View previous topic :: View next topic  
Author Message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Wed Sep 14, 2005 8:07 pm    Post subject: Re: recovering tcl files Reply with quote

sKy wrote:
Code:

         puts $file "proc $proc \{ [info args $proc] \} \{"
         puts $file "[info body $proc]"
         puts $file "\}"

Try this instead:
Code:
proc printproc proc {
   set args {}
   foreach arg [info args $proc] {
      if {[info default $proc $arg val]} {
         lappend args [list $arg $val]
      } {
         lappend args [list $arg]
      }
   }
   list proc $proc $args [info body $proc]
}
+
Code:
puts $file [printproc $proc]

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


Joined: 04 Apr 2004
Posts: 71
Location: Under The Sky

PostPosted: Sat Dec 03, 2005 2:48 am    Post subject: Match characters Reply with quote

Match characters

Bindings allow match characters in the arguments. Here are few special characters:

? matches any single character

* matches 0 or more characters of any type

% matches 0 or more non-space characters (can be used to match a single word)

~ matches 1 or more space characters (can be used for whitespace between words)
_________________
I'm an idiot, At least this one [bug] took about 5 minutes to find...
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Dec 14, 2005 4:49 am    Post subject: Reply with quote

while most people already learned they have to split the string text argument provided by many eggdrop binds into Tcl list first before using list commands on it, very few are aware that after using [split] extra white space will end up being empty list element(s), which will screw up argument indexing

here is one neat solution to this problem, from Tcler's wiki:

String to list: [split $s] alone operates on each instance of the splitchar (default:space), so sequences of spaces will produce empty list elements. [eval list $s] collapses whitespace sequences in one, but errors on unbalanced braces etc. The following proc should join the best of both worlds:

Code:

 proc string2list s {
        if [catch {eval list $s} res] {
                set res [list]
                foreach i [split $s] {
                        if {$i!=""} {lappend res $i}
                }
        }
        set res
 } ;#RS
 % string2list {a   b c     d}
 a b c d
 % string2list "a   b c  {"
 a b c \{
 % string2list {unbalanced "}
 unbalanced {"}

_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Fri May 26, 2006 8:21 am    Post subject: Reply with quote

demond wrote:
Code:

 proc string2list s {
        if [catch {eval list $s} res] {
                set res [list]
                foreach i [split $s] {
                        if {$i!=""} {lappend res $i}
                }
        }
        set res
 } ;#RS
 % string2list {a   b c     d}
 a b c d
 % string2list "a   b c  {"
 a b c \{
 % string2list {unbalanced "}
 unbalanced {"}

Try 'string2list {[exit]}' using that proc Razz The catch doesn't make any sense... RS must have created that proc before he learned Tcl Razz
Here's how i'd do it:
Code:
proc string2list s {
   set res [list]
   foreach i [split $s] {
      if {$i!=""} {lappend res $i}
   }
   set res
}


Edit: heh..i managed to provide a false solution the first time Razz Anyway here's another way to do the same ting:
Code:
proc string2list s {
   split [eval concat [split $s]]
}

_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Fri May 26, 2006 10:12 am    Post subject: Reply with quote

Code:
proc string2list {s {c "\n\t "}} {
   set res [list]
   foreach i [split $s $c] {
      if {$i!=""} {lappend res $i}
   }
   set res
}

If you want to improove split, why not at least include all features of split? Smile
I don't know exactly which characters are thread as whitespaces, but I am these 3 are the most common one Very Happy.

Edit: sorry, I wondered why you would need, since lappend creates if neccessary, but didn't think on empty strings Very Happy.

Edit3: final one doesnt work with $c.
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...


Last edited by De Kus on Sat May 27, 2006 4:53 am; edited 4 times in total
Back to top
View user's profile Send private message MSN Messenger
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Fri May 26, 2006 10:13 am    Post subject: Reply with quote

De Kus wrote:
Code:
proc string2list {s {c "\n\t "}} {
   foreach i [split $s $c] {
      if {$i!=""} {lappend res $i}
   }
   set res
}

If you want to improove split, why not at least include all features of split? Smile

Yes..that's a good idea Smile but you should keep the line creating the result variable. making lappend create it is not a good idea (pass your proc an empty string)
_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri May 26, 2006 11:23 am    Post subject: Reply with quote

Just to clarify, could you post the *final* string2list proc? The thread has gotten a bit confusing to this neophyte =)
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Fri May 26, 2006 2:37 pm    Post subject: Reply with quote

user wrote:

proc string2list s {
split [eval concat [split $s]]
}

That's the final one.
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat May 27, 2006 4:17 am    Post subject: Reply with quote

user wrote:

Try 'string2list {[exit]}' using that proc Razz The catch doesn't make any sense... RS must have created that proc before he learned Tcl Razz


where have you been? Smile

my fault I didn't quote DGP's remark right next to this thing:
Quote:

Note that this suffers from the same dangers as explained in the List well-formedness test above. Modifications for safety are left as an exercise for the reader (or the next Wiki visitor). You have been warned. - DGP

_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
sKy
Op


Joined: 14 Apr 2005
Posts: 194
Location: Germany

PostPosted: Sat May 27, 2006 5:04 pm    Post subject: Reply with quote

I know the string2list problem. That`s how i handle it right now.

Code:
# i use this

proc lremove { listname string } {
   return [lsearch -all -inline -not -exact $listname $string]
}

# or you could use this aswell too (lower memory usage)

proc lremove1 { listname string } {
   upvar $listname _list
   set _list [lsearch -all -inline -not -exact $_list $string]
}

# just an example
set result [exec process.exe -v]

foreach line [split $result "\n"] {
   # the first line will look like:
   #     ImageName   PID Threads Priority CPU Owner
   set line [split $line]
   # this is returned
   # {} {} {} {} {} {} {} ImageName {} {} PID Threads Priority CPU Owner
   # all those pointless {} doesn`t make it more easy to handle this list for futher things
   # so we just remove them
   set line [lremove $line {}]
   # the result will be
   # ImageName PID Threads Priority CPU Owner
   # perfect for me ;)
   #
   # from here do whatever you want
}


Quote:
Note that this suffers from the same dangers as explained in the List well-formedness test above. Modifications for safety are left as an exercise for the reader (or the next Wiki visitor). You have been warned. - DGP

I don`t really understand this.
But my method should be secure.

Comments wanted.
_________________
socketapi | Code less, create more.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Jun 03, 2006 2:25 am    Post subject: Reply with quote

sKy wrote:

Code:
# i use this

proc lremove { listname string } {
   return [lsearch -all -inline -not -exact $listname $string]
}

this won't work on older Tcl versions (lower than 8.4)
Quote:

Quote:
Note that this suffers from the same dangers as explained in the List well-formedness test above. Modifications for safety are left as an exercise for the reader (or the next Wiki visitor). You have been warned. - DGP

I don`t really understand this.

double evaluation; see my post about that somewhere in the FAQ section ("Script security" thread or something)
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Wed Jun 14, 2006 5:21 pm    Post subject: Don't Work vs Does Work Reply with quote

while :-
rm path/filename <--- does not work (to delete a file)
and
mv path/filename <--- does not work (to move a file)

file delete -- path/filename <--- does work
and
file copy -- path/filename(source) path(destination) <--- does work

so if your commands don't work do not despair
try :-

http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm
in the words of those that are here all the time RTFM

this link is hidden on this sight somewhere
_________________
It's times like this I wished I had listened to What my dad used to say. Can't say what it was I never listened.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Thu Jun 15, 2006 1:29 am    Post subject: Reply with quote

hah, a candid signature; if you had listened to your dad, perhaps you wouldn't be posting off-topic; what you had to say is hardly a Tcl tip, let alone a trick
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
NoZparker
Voice


Joined: 16 Feb 2004
Posts: 34

PostPosted: Thu Jun 15, 2006 1:42 am    Post subject: Reply with quote

Quote:
http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm
in the words of those that are here all the time RTFM

Is A tip

Quote:
hah, a candid signature; if you had listened to your dad, perhaps you wouldn't be posting off-topic; what you had to say is hardly a Tcl tip, let alone a trick

Is a critisism

and who do you think asked for the tip of the day in the first place.
Please keep critisisms to a private message.
_________________
It's times like this I wished I had listened to What my dad used to say. Can't say what it was I never listened.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Thu Jun 15, 2006 11:23 am    Post subject: Reply with quote

let me explain to you why it's NOT a tip

UNIX/Linux shell commands have nothing to do with Tcl; and simply pointing out some Tcl commands that have similar functionality does not constitute a tip in any way (a tip is, mind you, a helpful hint - which your RTFM statement is not)

moreover, apparently you have no idea what you are talking about; if the shell commands don't work on some file - because of permission modes/insufficient privileges - Tcl file commands won't work either

capisce?
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Tcl FAQ All times are GMT - 4 Hours
Goto page Previous  1, 2, 3, 4, 5  Next
Page 3 of 5

 
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