Leser: 1
2 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14
print 'Eingabe: ', eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm(1); my $buffer = ''; while (1) { my $tmp = ''; sysread(STDIN, $tmp, 1024); $buffer .= $tmp; } alarm(0); return $buffer; };
1
2
3
4
5
6
7
8
9
10
11
my $retval = eval {
local $SIG{ALRM} = sub { exit };
alarm 10;
my $input = '';
while (<>) {
$input .= $_;
}
alarm 0;
return $input;
};
print $retval;
QuoteIn both forms, the value returned is the value of the last expression evaluated inside the mini-program; a return statement may be also used, just as with subroutines.
1
2
3
4
5
6
7
8
9
my $input = '';
eval {
local $SIG{ALRM} = sub { die; };
alarm 3;
while (<>) {
$input .= $_;
}
};
print $input;
2 Einträge, 1 Seite |