Solved

print output in textarea

Posted on 2004-09-23
3
387 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

896 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

13 Experts available now in Live!

Get 1:1 Help Now