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: Donal K. Fellows <donal.k.fellows@manchester.ac.uk>
Date: Tue Dec 20 2005 - 16:59:46 CET

Bryan Oakley wrote:
> I'd probably still go with a single redefinition, with a traffic cop:
[...]
> It's not perfect, but personally I prefer that over the constant
> juggling of proc names.
>
> Thinking out loud for a moment... another way to accomplish it is to use
> interpreter aliases. Make 'puts' an alias either to the core puts or a
> special one, and toggle between them as needed:
[...]
> I think that may make the code more self-evident, but it's arguable
> which is truly better.

Another technique which works well (it's used in the TIP website
implementation) is to execute the code in a namespace other than the
root namespace, and define a command [puts] in that namespace that does
the capturing. This has the advantage of being easy to write, quick to
execute, and non-disruptive of other modules.

  namespace eval foo {
     proc puts args {
        # Example body...
        log $args
        eval puts $args
     }
     eval $script
  }

Donal.
Received on Fri Dec 23 19:02:31 2005