Quoting die:
- die LIST
If the last element of LIST does not end in a newline, the current script line number and input line number (if any) are also printed, and a newline is supplied.
But you probably want to use exit here.
| [reply] |
Other information you might find useful:
- If you include "\n" at the end of a message passed to the "die" or "warn" function, perl will not include "at {scriptname} line {N}" after the given message. That extra information only gets added to STDERR output when the string passed to die or warn does not end with "\n".
- You really should take a look at Pod::Usage -- I think it's one of the "core" modules (comes with perl); the examples in its man page should give you a nice idiom you'll want to use over and over.
- Pod::Usage works very well in combination with Getopt::Long, which is also a core module, and also well worth getting acquainted with, if you haven't used it yet.
Before I got hooked on Pod::Usage, my default template for command-line perl scripts included a line like:
my $Usage = "Usage: $0 \n";
and I would always put option flags, file args, etc, into that string, making it multi-line where appropriate, and if my arg checking indicated a need to give up (e.g. Getopt::Long returned false or some ad-hoc condition failed) that would lead to die $Usage;
But Pod::Usage is better, especially if you are in the (very good) habit of providing a decent POD man page in your command-line scripts, and you want to make it easy for users to see the man page.
With my old habit, I usually regretted having to repeat the content of my "$Usage" variable in the "SYNOPSIS" section of POD. With Pod::Usage, I just have the SYNOPSIS section in POD (no redundant "$Usage" variable). | [reply] [d/l] [select] |