help using multiple processes in a ptk program

[email protected] Sat, 20 Mar 2010 18:34:41 +0100
Newsgroups gmane.comp.lang.perl.tk
Message-ID <20100320173441.GA8517@laptop>
Hello, 

I am trying to set up a perl/tk program which needs to have a label
showing whether my ssh server is available or not. I would like not to
use threads, but instead multiple processes. I tried to combine
a few receipes from "Mastering Perl/Tk" by Steve Lidie and Nancy Walsh
and "Programming Perl" by Larry Wall et al. Somehow there must be a
problem of scoping here, which I somehow overlook:


#!/usr/bin/perl -w

use Tk;
use Net::Ping;
my $is_available;
my $ssh_host = "192.168.2.1";

sub fill_available_widget {
    $is_available = <IS_AVAILABLE>;
}


if (open(IS_AVAILABLE, "-|")) {
    my $mw = MainWindow->new;
    $mw->title("Hello");
    my $label = $mw->Label(-textvariable => \$is_available)->pack;
    $mw->fileevent(\*IS_AVAILABLE, 'readable',
		   [\&fill_available_widget, $label]); 
    $mw->Button(-text => "done", -command => sub {exit})->pack;
    $mw->bind('<q>', sub {exit});
    MainLoop;
}
else {
	my $p = Net::Ping->new();
	if ($p->ping($ssh_host)) {
	    print STDOUT "not available\n" }
	else {
	    print STDOUT "available\n"
	};
	$p->close();
	exit;
};


Does anybody have an idea?

Thank you a lot,

Gabriel
--++**==--++**==--++**==--++**==--++**==--++**==--++**==
ptk mailing list
[email protected]
https://mailman.stanford.edu/mailman/listinfo/ptk