I don't have much experience with perl/tk, but I'm using it for a script made to run on windows which gathers some data then creates and opens an html file with the output. The problem is that it's just too slow.
I wrote up a quick example to show the problem. All the interface does is provide a button to start doing the work but even that seems to take 30-45 seconds each time it's run.
Half a minute plus might not even sound that bad, but the results are near instant if I run the same thing after commenting out all the perl/tk stuff. I'm willing to take a hit in performance in exchange for the simple interface, but this seems excessive. I'm wondering if the problem is just that I'm not using more perl/tk specific ways of doing the same things which might run much faster.
Like I said, I'm not very familiar with perl/tk, in fact this is only the second time I've used it for something, so please forgive me my ignorance and while your in a forgiving spirit, please forgive my example code (it's ugly but does show the problem).
#!perl -w
use strict;
require Tk;
use Tk;
my $row=1;
my $filename="example_out.htm";
my %stuff1=(
'thing01_a' => "value01_a",
'thing02_a' => "value02_a",
'thing03_a' => "value03_a",
'thing04_a' => "value04_a",
'thing05_a' => "value05_a",
'thing06_a' => "value06_a",
'thing07_a' => "value07_a",
'thing08_a' => "value08_a",
'thing09_a' => "value09_a",
'thing10_a' => "value10_a"
);
my %stuff2=(
'thing01_b' => "value01_b",
'thing02_b' => "value02_b",
'thing03_b' => "value03_b",
'thing04_b' => "value04_b",
'thing05_b' => "value05_b",
'thing06_b' => "value06_b",
'thing07_b' => "value07_b",
'thing08_b' => "value08_b",
'thing09_b' => "value09_b",
'thing10_b' => "value10_b"
);
sub do_this() {
open FILE, "> $filename" or die "ERROR WRITTING FILE: $filename\nSyste
+m reported $!";
print FILE << "HTMLSTUFF";
<HTML>
<HEAD><TITLE>TABLE O' STUFF</TITLE>
<STYLE>
table {border-style: solid;border-width: 2;border-color: #005A80;}
td {padding:4px;border:0;text-align: center; white-space: nowrap}
.header {background-color: #005A80;text-decoration: none;text-align: c
+enter;color: white; font-weight: bold;}
.line2 {background-color: lightblue;}
.line1 {background-color: white;}
</STYLE>
</HEAD>
<BODY>
<P>
<TABLE>
<TR CLASS=header><TD>THING 1</TD> <TD>THING 2</TD> <TD>THING 3</TD> <T
+D>THING 4</TD> <TD>THING 5</TD> <TD>THING 6</TD> <TD>THING 7</TD> <TD
+>THING 8</TD> <TD>THING 9</TD> <TD>THING 10</TD></TR>
HTMLSTUFF
if ($row == 1) {print FILE "\n<TR CLASS=line1>"; $row=2;} elsif ($row
+== 2) {print FILE "\n<TR CLASS=line2>"; $row=1;}
foreach (sort keys(%stuff1) ) { print FILE "<TD CLASS=time>$stuff1{$_}
+</TD>";}
print FILE "</TR>";
if ($row == 1) {print FILE "\n<TR CLASS=line1>"; $row=2;} elsif ($row
+== 2) {print FILE "\n<TR CLASS=line2>"; $row=1;}
foreach (sort keys(%stuff2) ) { print FILE "<TD CLASS=time>$stuff2{$_}
+</TD>";}
print FILE "</TR>";
print FILE "\n</TABLE></BODY><HTML>";
close FILE;
system "start /b $filename";
}
my $fsize=12;
my $main = MainWindow->new();
$main->title("Button Window");
$main->configure(-background=>'#c0c0c0');
$main->optionAdd('*BorderWidth' => 1);
my $bottom = $main->Frame(-background=>'#c0c0c0')->pack(-expand=>0, -f
+ill=>'both');
my $sub_button=$bottom->Button(-width=>40, -background=>"#c0c0c0", -fg
+=>'black', -text=>'CLICK ME', -font => ['Courier', 10], -command=>\&c
+lick);
$sub_button->pack(-side => "bottom", -anchor => "s", -expand => "n", -
+fill => "none");
MainLoop();
sub click() {
do_this();
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.