In addition to specifying a #!
line, you can specify a short script
directly on the command line. Here are some of the possible ways to
run Perl:
Issue the perl command, writing your script line by line via -e switches on the command line:
perl -e 'print "Hello, world "' # Unix perl -e "print "Hello, world "" # Win32 or Unix perl -e "print qq[Hello, world ]" # Also Win32
Issue the perl command, passing Perl the name of your script as the first parameter (after any switches):
perl testpgm
On Unix systems that support the #!
notation, specify the Perl command on
the #!
line, make your script
executable, and invoke it from the shell (as described
above).
Pass your script to Perl via standard input. For example, under Unix:
echo "print 'Hello, world'" | perl - % perl print "Hello, world "; ^D
On Win32 systems, you can associate an extension (e.g., .plx) with a file type and double-click on the icon for a Perl script with that file type. Or, as mentioned earlier, do this:
(open a "DOS" window) C:> (edit your Perl program in your favorite editor) C:> pl2bat yourprog.plx C:> .yourprog.bat (program output here)
If you are using the ActiveState version of Win32 Perl, the installer normally prompts you to create the association.
On Win32 systems, if you double-click on the icon for the Perl executable, you’ll find yourself in a command-prompt window with a blinking cursor. You can enter your Perl commands, indicating the end of your input with Ctrl-Z, and Perl will compile and execute your script.
Perl parses the input file from the beginning, unless you’ve
specified the -x switch (see Section 3.2 later in this
chapter). If there is a #!
line, it
is always examined for switches as the line is being parsed. Thus,
switches behave consistently regardless of how Perl was
invoked.
After locating your script, Perl compiles the entire script into
an internal form. If there are any compilation errors, execution of
the script is not attempted. If the script is syntactically correct,
it is executed. If the script runs off the end without hitting an
exit
or die
operator, an implicit exit(0)
is provided to indicate successful
completion.
3.133.124.145