Command Processing
It is fortunate that Perl grew up in the Unix world, because that means its invocation syntax works pretty well under the command interpreters of other operating systems, too. Most command interpreters know how to deal with a list of words as arguments and don’t care if an argument starts with a minus sign. There are, of course, some sticky spots where you’ll get fouled up if you move from one system to another. You can’t use single quotes under MS-DOS as you do under Unix, for instance. And on systems like VMS, some wrapper code has to jump through hoops to emulate Unix I/O redirection. Wildcard interpretation is a wildcard. Once you get past those issues, however, Perl treats its switches and arguments much the same on any operating system.
Even when you don’t have a command interpreter per se, it’s easy to
execute a Perl program from another program written in any language. Not
only can the calling program pass arguments in the ordinary way, it can
also pass information via environment variables and, if your operating
system supports them, inherited file descriptors (see “Passing
Filehandles” in Chapter 15). Even exotic argument-passing
mechanisms can easily be encapsulated in a module, then brought into your
Perl program via a simple use
directive.
Perl parses command-line switches in the standard fashion.[171] That is, it expects any switches (words beginning with a minus) to come first on the command line. After that usually comes the name of the script, followed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access