Solved

print output in textarea

Posted on 2004-09-23
3
386 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now