Gossamer Forum
Home : General : Perl Programming :

Perl Tk, redirect STDOUT to Scrolled() textfield

Quote Reply
Perl Tk, redirect STDOUT to Scrolled() textfield
I need to redirect STDOUT output, after a perl format has been applied, to populate a Scrolled text field. I'm filtering values from a CSV file compared to user input, and displaying them in nice columns with headers and such...I did try using a custom swrite function (using $^A to accumulate the lines), as well as using a buffer to populate an array, but none seemed to work quite right...but that's probably my fault ;) I'm trying to avoid using a temp file, then reading it into the text field, but I'm beginning to feel it's the only way! (But there's more than one way I bet) Any help, ideas, or resources I need to check are greatly appreciated!

#the scrolled list box....

$result = $mw->Scrolled("Text",-scrollbars=>'e')->pack();

sub search{
my $selected = shift;
$result->delete('end','1.0');
#open CSV file for searching
open(FH,"$file") or die "Error: Can't open csv file.\n";
while(<FH>)
{
$current = ((split "\t",$_)[0]);
$customer = ((split "\t",$_)[1]);
$description = ((split "\t",$_)[2]);
$fee = ((split "\t",$_)[3]);
$expense = ((split "\t",$_)[4]);

if($current=~/$selected/)
{
#counter
&increment;
#Here's where I need to redirect output to
#the Scrolled field instead of console
write;
#$result->insert('end', $_);
}
}
close(FH);
$result->insert('end',"-------------\n");
$result->insert('end',"$rc record(s) found.\n");
}

###formatting instructions###
format STDOUT_TOP =

Search Program
CURRENT DESCRIPTION CUSTOMER FEE EXPENSE
_____________________________________________________________________________________________________________________
.
format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<@>>>>>>>>>>>>>>>>>>@>>>>>>>>>>>
$current $description $customer $fee $expense
.
###end formatting instructions###
Quote Reply
Re: [lnx.kid] Perl Tk, redirect STDOUT to Scrolled() textfield In reply to
you can use 'tie' to assign a handle to the text area and then route stdout to this via typeglobs.

Code:
use vars qw(*OUTPUT);
tie (*OUTPUT, 'Tk::Text', $result) or die "Error tie'ing to result: $!\n";
*STDOUT = *OUTPUT;

but it would probably be a more elegant solution to have your code that does the actual output just print to the OUTPUT handle.

-g

s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: [GClemmons] Perl Tk, redirect STDOUT to Scrolled() textfield In reply to
Excellent! Thanks-much!

Seems like that would work using 'print' or 'printf', but I'm running into yet another significant problem....In order to have my data formatted, I need to use 'write()', otherwise the format won't be applied....looks like the following link just about sums it up:

http://archive.develooper.com/...rl.org/msg70665.html