Hi All,

I'm writing a perl application using Tk for the gui, and wish to write
formatted
output to a logging window within the gui. But I cannot get write to do
as I wish,
and think that I don't really understand filehandles so well. Any
insight on them 
would be greatly appreciated.

  I have the following (shortened) code that illustrates my problem,
when run 
from the command line (Unix or Win). I can print to the logging window,
but not write 
(formatted output) to it. Is it that Tk::Text doesn't give a true
filehandle? Any way
to do this using only standard modules (those that come by default with
Perl)?

Thanks,

John

------------------------------------------------------------------------
-------

#!/usr/local/PERL_5.005_03/bin/perl -w

use Tk;
use FileHandle;

$mw = new MainWindow;

$report = $mw->Button(-text=>'Report',-command=>\&report);
$e      = $mw->Button(-text=>'Exit',-command=>sub{exit 0;});
$report->pack($e);

$log = $mw->Text()->pack();
tie (*LOG, 'Tk::Text', $log);

MainLoop();

exit 0;

#--------------------------------------------------

sub report() {
    my ($f1, $f2, $f3) = ('F1','F2','F3');

    format SOURCES_TOP =
field1 field2 field3
------ ------ ------
.

    format SOURCES =
@||||| @||||| @||||| 
$f1,   $f2,   $f3
.
    
    $ofh = *LOG;       # using this instead of *STDOUT gives command
line errors
#    $ofh = *STDOUT;

    select($ofh);
    $ofh->format_name("SOURCES");
    write $ofh;

    &logit("wrote to $ofh");

}

#--------------------------------------------------
sub logit() {
    return unless $log;

    # this always prints to Tk::Text widget correctly
    for (@_) { print LOG $_, "\n"; } 
}


Reply via email to