Basic Concepts
A Perl program is a bunch of Perl statements and definitions thrown into a file. You can execute the file by invoking the Perl interpreter with the script name as an argument. You will often see a line
#
!/usr/bin/perlas the first line of a Perl script. This line is a bit of magic
employed by UNIX-like operating systems to automatically execute
interpreted languages with the correct command interpreter. This line
is called a shebang
line due to the first two characters:
# is sometimes called sharp, and
! is sometimes called bang. This line normally
won’t work for Perl-for-Win32 users,[5]
although it doesn’t hurt anything since Perl sees lines
beginning with # as comments.
The invocation examples that follow assume that you have invoked the Windows NT command interpreter (cmd.exe) and are typing into a console window. You can run Perl scripts from the Explorer or the File Manager (assuming that you’ve associated the script extension with the Perl interpreter) by double-clicking on the script icon to launch it. Throughout this book, we’re going to be discussing standard output and input streams; these are generally assumed to be your console window.
We recommend naming scripts with a .plx extension. Traditionally, Perl modules have a .pm extension, and Perl libraries have a .pl extension. The ActiveState installer prompts you to associate .pl with the interpreter.
You can always execute a script by calling the Perl interpreter with the script as an argument:
> perl myscript.plx ...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