Solved

print output in textarea

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl count the hash for print 4 165
collecting information 2 158
Regular Expression question to filter with negation. 6 95
html form to write data to csv 24 114
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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 …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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