by markobr » Sun Sep 27, 2020 9:40 pm
Does the script do any killing? It just "killls" itself. Any opposite? So, no. Is the script subjected to killing? Yes, insofar as it kills itself. To the opposite? No.
Is the command "die"? Yes. Something like "[do something] or die"? And, yes, exactly this. You solved it.
Or is it "exit"? So, no.
"Delete yourself?" No.
***** SPOILER ALERT *****
This is the story of Alice, a Perl programmer, or it could be the story of many more Perl programmers (Including me). Perl is a computer language which is quite lenient when it's about runtime errors. You try to open a file for reading, but the file doesn't exist? In most languages the standard would be that the program exits with an error message. Not so in Perl - there, the reasoning is - well, if there is no file at all, there's nothing to read, as it would be with en existing, but empty file. So no exit, but the program just continues with the input from said file being empty. There are many more cases where Perl would continue and just assume there's nothing to do here, but this should be fine. But the non-existent file sure is the most common case. Perl will, however, return a false value in such a situation.
While Perl's behaviour often is quite practical (you don't have to care about minor problems), it can often enough be quite a problem. If you expect a file to exist (even if it may be empty), you may want to know that before you proceed with processing the missing data. So you want to tell the program to exit with an error message instead of just continuing. Now, the command for just doing that in Perl is "die". So, if you want your program tos stop because of an error, you tell it to "die".
Now Perl (and many other programming languages) have the logical "or" working in this way: When the first part of the "or" statement evaluates to "true", the second part won't be evaluated at all, but will simply be ignored. So, if your statement" A or B" is executed, and A returns a true value, B won't be processed at all.
Now, if you want to make sure as a Perl programmer that your program stops with an error (or invokes special error handling code) in case of a missing file (or quite a lot of other problems), you will write "or die" after the statement in question. If the statement returns a true value (and supposedly succeded), the statement after the "or" will be ignored. If it returns false, it will e executed causing the program to stop with an error message (or invoke specific error handling code). So it can be quite common for a Perl programmer to write lines like
open <FILEHANDLE>, "file.txt" or die;
to ensure the program breaks in case "file.txt" doesn't exist at all. But this surely looks like you want to threaten the computer with death in case it is unable or unwilling to do what you want.