Re: (newbie) storing outputs from all lines of procs into a string
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: (newbie) storing outputs from all lines of procs into a string

From: Bryan Oakley <oakley@bardo.clearlight.com>
Date: Wed Dec 21 2005 - 19:14:47 CET

just80n@gmail.com wrote:
> Here is my last version of DYN_ex ...
>
> proc DYN_ex args \
> {
> global OUTPUT
> set OUTPUT ""
> set COMMAND ""
> foreach arg $args {append COMMAND $arg;append COMMAND " "}
> set COMMAND [string trim $COMMAND]

The previous three statements could be replaced with this:

     set COMMAND [string trim [join $args " "]]

> rename puts _puts
> proc puts args { append ::OUTPUT $args "\n"; eval _puts $args}

You want to change that append statement to:

     append ::OUTPUT [join $args " "] "\n"

>...
> however when when I launch the choucroute proc (see my last message), I
> still get
>
> % DYN_ex choucroute
> qdsfsd 33
> qdsfsd 4444 4
> {qdsfsd 33}
> {qdsfsd 4444 4}
> choucroute
>
>
> append output [join $retoureval " "] does not help; I still get those
> { { { }} }
>
> any idea ?

The {}'s are coming from the renamed puts code. $args is a list; when
Tcl prints a list it will add {}'s to guarantee the string you get can
be used to reconstruct the list precisely. Join is a handy way to
convert a list into a space-separated string of words (assuming the list
doesn't have any nested lists)
Received on Fri Dec 23 19:02:50 2005