Solved

print output in textarea

Posted on 2004-09-23
3
391 Views
Last Modified: 2008-02-01
Hi..
i would like to know how can i print the output generate by the sub-condition onto the
text area of the perl tk gui.

This is how i create my text area using perl tk:

#Create Scrollbar widget and setting it's entity
 
$xscroll = $frame7->Scrollbar(-orient => 'horizontal');
$yscroll = $frame7->Scrollbar(-orient => 'vertical');

# Create text widget($text)and setting it to uneditable & other entity  
my $text = $frame7->ROText('-width'=>70,'-height'=>20,
-xscrollcommand => ['set', $xscroll],
-yscrollcommand => ['set', $yscroll]);
$xscroll->configure(-command => ['xview', $text]);
$yscroll->configure(-command => ['yview', $text]);
$xscroll->pack(-side => 'bottom', -fill => 'x');
$yscroll->pack(-side => 'right', -fill => 'y');
$text->pack(-side=>'top', -fill => 'both', -expand => 1);

This is the sub-condition i use to crunch data and save the crunched data into text files.
sub condition1()
{

#Get entry
      $mac=$f->get('active');
        $dev=$d->get('active');
        $datef=$entry2->get;
        $datet=$entry3->get;
      $file=$entry->get;

#connect to the database
my $dbh = DBI->connect('dbi:mysql:rvsi','','', {RaiseError=>1, PrintError=>1});

# Extract the data from database
my $d = $dbh->selectall_arrayref("select qin, qout, yield, reject FROM yield WHERE date BETWEEN '$datef' AND '$datet'");
    print ("Daily Yield Report Summary for '$dev' between '$datef' to '$datet'\n\n");
    print ("Qin\t", "Qout\t", "Yield\t", "Reject\n");

# Print out all the array catch  
foreach my $r(@$d) {
    print join("\t", @$r), $/;
}

#print the dotted line
print "-"x60, $/;

#Do the calculation
my $t = $dbh->selectrow_arrayref("select sum(qin), sum(qout), ((sum(qout)/sum(qin))*100), sum(reject) FROM yield WHERE date BETWEEN '$datef' AND '$datet'");
print join("\t", @$t), $/;

die "$file already exists\n" if -f $file;
open FILE, ">$file" or die "Can not create $file $!\n";

#print the sums at the top of the file, separated by tabs
print FILE "Daily Yield Report Summary\n";
print FILE "Device: '$dev'\n";
print FILE "Date: '$datef' to '$datet'\n\n";
print FILE "Qin\t", "Qout\t", "Yield\t", "Reject\n";
foreach my $r(@$d) {
print FILE join("\t", @$r), $/;}

#write the other arrays in tab-separated columns underneath the sums
 print FILE  "-"x60, $/;
 print FILE join("\t", @$t), $/;

close(FILE);
}
0
Comment
Question by:TPoly
  • 2
3 Comments
 
LVL 5

Expert Comment

by:ZiaTioN
ID: 12145469
replace:
print join("\t", @$r), $/;

with:
$text ->insert("end",  "$r\n");

You can do your own formatting as far as the \t (tab) goes. Maybe something like " $r .= "\t"; before the insert() function.
0
 
LVL 5

Accepted Solution

by:
ZiaTioN earned 250 total points
ID: 12145516
For future reference you can check out a text editor I wrote in perl/Tk at the following link: http://www.perlskripts.com/cgi-bin/showscript.cgi?pEdit=1

I coded a ton of Tk functions and commented pretty well so you may be able to find what you are looking for in this code. If you want to download this app and use it visit the site directly (www.perlskripts.com) and navigate to the scripts ection. There are some support file you will need to grab in order to make this program complete. The first link I gave is strictly for the source code.
0
 

Author Comment

by:TPoly
ID: 12157413
it is unable to print the output on the text area.

beside, i also want to know to how to print a "file created successful"

or

die "$file already exists\n" if -f $file;
open FILE, ">$file" or die "Can not create $file $!\n";

in the textarea

thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl, group, sort, count question 6 150
Using Perl to parse rows 7 101
Perl Application JSON Receiving Strange Java Error 3 79
Perl script to delete older files 6 94
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question