=head1 NAME
-perlfaq8 - System Interaction ($Revision: 1.23 $, $Date: 2005/01/03 18:43:37 $)
+perlfaq8 - System Interaction ($Revision: 1.25 $, $Date: 2005/06/04 04:12:40 $)
=head1 DESCRIPTION
If you expect characters to get to your device when you print() them,
you'll want to autoflush that filehandle. You can use select()
and the C<$|> variable to control autoflushing (see L<perlvar/$E<verbar>>
-and L<perlfunc/select>, or L<perlfaq5>, ``How do I flush/unbuffer an
-output filehandle? Why must I do this?''):
+and L<perlfunc/select>, or L<perlfaq5>, "How do I flush/unbuffer an
+output filehandle? Why must I do this?"):
$oldh = select(DEV);
$| = 1;
generates a signal which is sent to your terminal's currently
foregrounded process group, which you then trap in your process.
Signals are documented in L<perlipc/"Signals"> and the
-section on ``Signals'' in the Camel.
+section on "Signals" in the Camel.
-You can set the values of the %SIG hash to be the functions you want
+You can set the values of the %SIG hash to be the functions you want
to handle the signal. After perl catches the signal, it looks in %SIG
for a key with the same name as the signal, then calls the subroutine
value for that key.
# as an anonymous subroutine
-
+
$SIG{INT} = sub { syswrite(STDERR, "ouch\n", 5 ) };
-
+
# or a reference to a function
-
+
$SIG{INT} = \&ouch;
-
+
# or the name of the function as a string
-
- $SIG{INT} = "ouch";
+
+ $SIG{INT} = "ouch";
Perl versions before 5.8 had in its C source code signal handlers which
would catch the signal and possibly run a Perl function that you had set
Perl's exception-handling mechanism is its eval() operator. You can
use eval() as setjmp and die() as longjmp. For details of this, see
the section on signals, especially the time-out handler for a blocking
-flock() in L<perlipc/"Signals"> or the section on ``Signals'' in
+flock() in L<perlipc/"Signals"> or the section on "Signals" in
the Camel Book.
If exception handling is all you're interested in, try the
Use the alarm() function, probably in conjunction with a signal
handler, as documented in L<perlipc/"Signals"> and the section on
-``Signals'' in the Camel. You may instead use the more flexible
+"Signals" in the Camel. You may instead use the more flexible
Sys::AlarmCall module available from CPAN.
The alarm() function is not implemented on all versions of Windows.
you need to figure out the problem.
#!/usr/bin/perl -w
-
+
BEGIN {
$SIG{__WARN__} = sub{ print STDERR "Perl: ", @_; };
$SIG{__DIE__} = sub{ print STDERR "Perl: ", @_; exit 1};
}
-
+
$a = 1 + undef;
$x / 0;
__END__
get a new F<perl> binary with your extension linked in.
See L<ExtUtils::MakeMaker> for more details on building extensions.
-See also the next question, ``What's the difference between require
-and use?''.
+See also the next question, "What's the difference between require
+and use?".
=head2 What's the difference between require and use?