Namespace Tk::ForDummies::STDOUT

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am using Perl Tk and sometimes, I need to redirect STDOUT in a Text
or ROtext widget (scrolled or not).

To redirect STDOUT progressivly, we can use Tk::Text or Tk::ROText and
use tie. the problem is that there is bug when I use syswrite. It is
also not work if we use a scrolled widget.

I have found a solution by using Tie::Handle and using tie as
tie *STDOUT, qq(MyPackage), $tkObject;

Then, I have wrote a .pm (100 lines code) and it is very simple.

I have seen that there is not Tk::STDOUT module or function , but
Tk::Error function exists if you use Tk.

Do you think if it is a good idea to create a module named
Tk::ForDummies::STDOUT ?

Synopsis example :

use warnings;
use strict;
use Tk::ForDummies::STDOUT;
use POSIX 'acos';
use Tk;

my $mw = MainWindow->new;

my $Scrolled = $mw->Scrolled(
    -height => 10,
    -wrap       => "none",
    -relief     => "solid",
    -background => "white",
    -scrollbars => "osoe",
)->pack(qw/ -side bottom -pady 15 -padx 15 -fill both -expand 1 /);

tie *STDOUT, 'Tk::ForDummies::STDOUT', $Scrolled;

for ( 1 .. 5 ) {
    print "Hello Text World!\n";
    my $toto = sprintf( "%.3f", 123.456789 );
    syswrite( *STDOUT, "$toto\n" );


Re: Namespace Tk::ForDummies::STDOUT wrote:
Quoted text here. Click to load it


If that was its name, I wouldn't expect I'd have to tie it to STDOUT explicitly
as you do below.
Why is it 'ForDummies'?
The issue with scrolled widgets can be worked around by calling
$w->Subwidget('scrolled') to get access to the wrapped target widget like so:

tie *STDOUT, 'Tk::Text', $Scrolled->Subwidget('scrolled');

Maybe it would be easier to submit a patch that implements Tk::Text::WRITE() ?

Cheers, Christoph

Quoted text here. Click to load it

   display/edit a list of values in a Set of Widgets.
   display/edit a list of choices in a Set of single-selection Widgets.

Re: Namespace Tk::ForDummies::STDOUT

Quoted text here. Click to load it

Thank you for your response.
tie *STDOUT, 'Tk::Text', $Scrolled->Subwidget('scrolled'); work well,
I had fogotten to use subwidget.

I think that it is an easier way to submit a patch that implements
Tk::Text::WRITE() as you say. I have search and found
The module use also PRINT and PRINTF, but not WRITE, that's why
syswrite doens't work.

How can I submit a patch ? By send an email to SREZIC, or in ?

Best Regards

Site Timeline