in reply to Re^4: Understanding compiletime vs. runtime
in thread Understanding compiletime vs. runtime
So let me state facts about how Perl works.
sub warn { my @messages = @_; unless (@messages) { @messages = "Warning: something's wrong"; } if ($messages[-1] !~ /\n$/) { my ($package, $file, $line) = caller(); $messages[-1] .= " at $file line $line\n"; } if ($SIG{__WARN__}) { $SIG{__WARN__}->(@messages); } else { print STDERR @messages; } }
sub die { my @messages = @_; unless (@messages) { @messages = "Warning: something's wrong"; } if ($messages[-1] !~ /\n$/) { my ($package, $file, $line) = caller(); $messages[-1] .= " at $file line $line\n"; } if ($SIG{__DIE__}) { $SIG{__DIE__}->(@messages); } foreach level (travel up the callstack) { if (this level is trapping exceptions) { $@ = join "", @messages; transfer control to where that's caught. } } unless ($SIG{__DIE__}) { print STDERR @messages; exit(255); } }
Going to a higher level of explanation, it is because Larry Wall thought that it would be more useful to trap die than warn. And it is useful because the primary thing that die does is change the flow of the program, and someone might want to regain control somewhere. By contrast the primary thing that warn does is print to STDERR, and people can already control STDERR.
However I'll give you a random warning. A common problem with Unix systems is that people write daemons like this and expect them to always be up. Then months later the system reboots, and people have forgotten about the necessary daemons. Then things break and it is really hard to track down why.
The solution is that if you write something that you really want to always be running, just have it try to launch regularly from cron, check if it needs to run (checking for a a control file is a common way to do this), and if it does, then run it. Otherwise have it quietly exit.
|
---|