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?
Yes..that's a good idea 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)
user wrote:
Try 'string2list {[exit]}' using that proc The catch doesn't make any sense... RS must have created that proc before he learned Tcl
where have you been?
my fault I didn't quote DGP's remark right next to this thing:
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
# 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
}
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.
# 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)
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
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
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.
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
[02:08:55] <user> .sh
[02:08:55] <bot> Tcl: Type 'exit' to return to the real world.
[02:09:07] <user> proc errortest {} {
[02:09:08] <user> invalid
[02:09:09] <user> }
[02:09:09] <bot>
[02:09:12] <user> errortest
[02:09:12] <bot> invalid command name "invalid"
[02:09:12] <bot> while executing
[02:09:12] <bot> "invalid"
[02:09:12] <bot> (procedure "errortest" line 2)
[02:09:17] <user> exit
[02:09:17] <bot> *** user has joined the party line.
[02:09:17] <bot> You have no messages.
EDIT: typo
Last edited by user on Tue Jan 02, 2007 2:29 pm, edited 1 time in total.