Hi everyone,

I tried to create a little GUI for a program which I wrote a while ago.
It's only a little link filter. I have to give him an URL, he parses the
website for given regular expressions and gives back a HTML file with
all the links in it.
Now the problem is that if i enter the URL and click on the Button to
proceed, the program hangs for about 30 seconds before it goes on.
Everything works fine. Only this "lag" is very disappointing. I can't
find my mistake...
If I do the same on the console, everything works instantly without hanging.
I would be glad if someone could help me out. :)

Here's the code:

use LWP::UserAgent;
use HTTP::Cookies::Mozilla;
use Win32::GUI();

# Use of the Firefox Cookie file
# For German Systems: Change the Docume~1 to Dokume~1
# I'm working on a better solution for this
$kekse = HTTP::Cookies::Mozilla->new( 'file' =>
glob("C:/Docume~1/$ENV{'USERNAME'}/Anwendungsdaten/Mozilla/Firefox/Profiles/*.default/cookies.txt"));

# Creation of the LWP Useragent with the Firefox Cookie file
$ua = LWP::UserAgent->new;
$ua->agent('Mozilla/5.0');
$ua->cookie_jar($kekse);

# Creation of the GUI
$main = Win32::GUI::Window->new(
    -name   => 'Main',
    -width  => $width = 295,
    -height => $height = 161,
    -maximizebox => 0,
    -resizable => 0,
    -text => 'Link Filter',
    );

$lblURL = $main->AddLabel(
    -name => 'lblURL',
    -width => 100,
    -height => 17,
    -align => 'left',
    -left => 4,
    -top => 4,
    -text => 'Bitte URL eingeben:',
);

$tfURL = $main->AddTextfield(
    -name => 'tfURL',
    -width => 281,
    -height => 77,
    -align => 'left',
    -left => 4,
    -top => 20,
    -multiline => 1,
    );

$btGet = $main->AddButton(
    -name => 'btGet',
    -width => 279,
    -height => 33,
    -left => 5,
    -top => 100,
    -text => 'Get Them!',
);

$desk = Win32::GUI::GetDesktopWindow();
$deskwidth = Win32::GUI::Width($desk);
$deskheight = Win32::GUI::Height($desk);
$deskx = ($deskwidth - $width) / 2;
$desky = ($deskheight - $height) / 2;
$main->Move($deskx, $desky);
$main->Show();

Win32::GUI::Dialog();

sub Main_Terminate {
    return -1;
}

sub btGet_Click {
        # Copy the entered URL into a usable variable
        $url = $tfURL->Text;
    return -1;
}

# Get the content of the Website and save it into a temporary HTML file
$ua->get($url, ':content_file' => 'temp.html');

open(EINGABE, "temp.html") || die("Fehler: Datei temp.html konnte nicht
gefunden werden.");
open(AUSGABE, ">links.html") || die("Fehler: konnte Datei rs.html nicht
erstellen.");

# Filter the links from the temporary file and write them into a new
HTML file
while($zeile = <EINGABE>) {
        if ($zeile =~ m/ENTER YOUR REGEXP HERE/) {
                $zeile =~ s/ENTER YOUR REGEXP HERE/AND HERE/;
                print AUSGABE "<a href=\"" . $zeile . "\">" . $zeile . "</a>" . 
"<br>";
        }
}

close(EINGABE);
close(AUSGABE);

# Delete temporary file
unlink "temp.html";

# Open the file which holds the filtered links
`links.html`;



Reply via email to