How to Do It
Gee, right about now you’re probably wondering how to run a Perl program. The short answer is that you feed it to the Perl language interpreter program, which coincidentally happens to be named perl. The long answer starts out like this: There’s More Than One Way To Do It.[18]
The first way to invoke perl
(and the way most likely to work on any operating system) is to simply
call perl explicitly from the command
line.[19] If you are doing something fairly simple, you can use the
–e switch (% in the following example represents a
standard shell prompt, so don’t type it). On Unix, you might
type:
% perl –e 'print "Hello, world!\n";'On other operating systems, you may have to fiddle with the quotes some. But the basic principle is the same: you’re trying to cram everything Perl needs to know into 80 columns or so.[20]
For longer scripts, you can use your favorite text editor (or any other text editor) to put all your commands into a file and then, presuming you named the script gradation (not to be confused with graduation), you’d say:
% perl gradationYou’re still invoking the Perl interpreter explicitly, but at least you don’t have to put everything on the command line every time. And you no longer have to fiddle with quotes to keep the shell happy.
The most convenient way to invoke a script is just to name it directly (or click on it), and let the operating system find the interpreter for you. On some systems, there may be ways of associating various file extensions or directories ...
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