lhp@nereida:~/Lperl/src$ cat -n eval_alarm.pl 1 #!/usr/bin/perl -w 2 use strict; 3 4 sub time_out { 5 die "Cansados de esperar"; 6 } 7 8 my $lim = (shift or 1); 9 my $buf = ""; 10 11 local $SIG{ALRM} = "time_out"; 12 print "Write your input: "; 13 eval { 14 alarm($lim); # Le indica al SO enviar una señal de ALRM cada $lim s. 15 $buf = <>; 16 alarm(0); # Cancela la alarma 17 }; 18 print "\n"; 19 print "Error \$\@ is: $@" if $@; 20 print "Buffer has: <$buf>\n";Ejemplo de ejecución:
lhp@nereida:~/Lperl/src$ eval_alarm.pl Write your input: Error $@ is: Cansados de esperar at ./eval_alarm.pl line 5. Buffer has: <> lhp@nereida:~/Lperl/src$ eval_alarm.pl 10 Write your input: my input Buffer has: <my input > lhp@nereida:~/Lperl/src$
Casiano Rodríguez León