#!/usr/bin/perl use warnings; use strict; use Glib; # Glib provides a few ready-made event sources, # Glib::Timeout, Glib::Idle, and Glib::IO->add_watch # read perldoc Glib::MainLoop my $main_loop = Glib::MainLoop->new; my $count = 1; my $timer = Glib::Timeout->add (1000, \&timer_callback, undef, 1 ); #my $timer = Glib::Timeout->add ($interval, $callback, $data=undef, $pri- # ority=G_PRIORITY_DEFAULT) # * $interval (integer) number of milliseconds # * $callback (subroutine) # * $data (scalar) # * $priority (integer) # Run $callback every $interval milliseconds until $callback returns # false. Returns a source id which may be used with # "Glib::Source->remove". Note that a mainloop must be active for # the timeout to execute. sub timer_callback{ $count++; print "$count\n"; return 1; } my $count1 = 1; my $timer1 = Glib::Timeout->add (100, \&timer1_callback, undef, 1 ); sub timer1_callback{ $count1++; print "\t$count1\n"; return 1; } ### filehandle watch open (FH, "+> test.log") or warn "$!\n"; Glib::IO->add_watch (fileno 'FH', ['in'], \&watch_callback, 'FH', 1 ); # integer = Glib::IO->add_watch ($fd, $condition, $callback, $data=undef, $priority=G_PRIORITY_DEFAULT) # * $fd (Glib::IO) file number, e.g. fileno($filehandle) # * $condition (Glib::IOCondition) # * $callback (subroutine) # * $data (scalar) # * $priority (integer) $main_loop->run; #################################################################### sub watch_callback { my ($fd, $condition, $fh) = @_; my @lines = ; print @lines; #always return TRUE to continue the callback return 1; }