El siguiente ejemplo resume el modo de uso:
pp2@nereida:~/src/perl/Event$ cat -n agenda.pl 1 #!/usr/local/bin/perl 2 use warnings; 3 use strict; 4 5 use Event qw(loop unloop); 6 use DateTime; 7 8 Event->io(fd => \*STDIN, poll => 'r', cb => \&io); 9 10 loop; 11 12 sub io { 13 my $cmd = <STDIN>; 14 chomp $cmd; 15 return unless $cmd; 16 17 if (uc($cmd) eq 'Q') { 18 unloop; 19 return 20 } 21 22 unless ($cmd =~ /^(\d+)\s+(.+)/) { 23 warn"Error: Wrong format in <$cmd>\n" ; 24 return 25 } 26 my ($period, $msg) = ($1, $2); 27 28 my $at = time()+$period; 29 Event->timer( 30 prio => 2, 31 at => $at, 32 cb => sub { 33 warn "\nAlarm:\a $msg\n"; 34 $_[0]->w->cancel; 35 }, 36 repeat => 0, 37 ); 38 39 my $dt = DateTime->from_epoch( epoch => $at, time_zone => 'UTC' ); 40 warn "Alarm scheduled for $msg at $dt.\n"; 41 42 }
Casiano Rodríguez León