If the program is syntactically correct, it is executed. If the program runs off the end without hitting an exit or die operator, an implicit exit 0 is provided to indicate successful completion. If you install Perl by other means including building from the sources , you may have to modify the Registry yourself.
Note that this means you can no longer tell the difference between an executable Perl program and a Perl library file. This incantation is a bit much to remember, but Perl will display it for you if you say perl "-V:startperl". Command-interpreters on non-Unix systems have rather different ideas on quoting than Unix shells.
On some systems, you may have to change single-quotes to double ones, which you must not do on Unix or Plan 9 systems. The problem is that none of this is reliable: it depends on the command and it is entirely possible neither works. If 4DOS were the command shell, this would probably work better:. EXE in Windows NT slipped a lot of standard Unix functionality in when nobody was looking, but just try to find documentation for its quoting rules.
It may seem obvious to say, but Perl is useful only when users can easily find it. If that can't be done, system administrators are strongly encouraged to put symlinks to perl and its accompanying utilities into a directory typically found along a user's PATH, or in some other obvious and convenient place.
In this documentation,! You are advised to use a specific path if you care about a specific version. As with all standard commands, a single-character switch may be clustered with the following switch, if any. A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. If there are no digits, the null character is the separator. Other switches may precede or follow the digits.
For example, if you have a version of find which can print filenames terminated by the null character, you can say this:. The special value 00 will cause Perl to slurp files in paragraph mode. Any value or above will cause Perl to slurp files whole, but by convention the value is the one normally used for this purpose.
You can also specify the separator character using hexadecimal notation: -0x HHH Unlike the octal form, this one may be used to specify any Unicode character, even those beyond 0xFF. So if you really want a record separator of , specify it as -0x1FF.
This means that you cannot use the "-x" option with a directory name that consists of hexadecimal digits, or else Perl will think you have specified a hex number to An implicit split command to the F array is done as the first thing inside the implicit while loop produced by the "-n" or "-p". As of 5. The letters, their numeric values, and effects are as follows; listing the letters is equal to summing the numbers.
Repeating letters is just redundant, not cumulative nor toggling. This has no effect on code run in modules. This behaviour follows the implicit and problematic UTF-8 behaviour of Perl 5. This variable is set during Perl startup and is thereafter read-only. If you want runtime effects, use the three-arg open see "open" in perlfunc , the two-arg binmode see "binmode" in perlfunc , and the open pragma see open. In Perls earlier than 5. This feature was practically unused, however, and the command line switch was therefore "recycled".
Note: Since perl 5. See perldebug. If t is specified, it indicates to the debugger that threads will be used in the code being debugged. This switch is enabled only if your perl binary has been built with debugging enabled: normal production perls won't have been.
For example, to watch how perl executes your program, use -Dtls. Another nice value is -Dx , which lists your compiled syntax tree, and -Dr displays compiled regular expressions; the format of the output is explained in perldebguts.
As an alternative, specify a number instead of list of letters e. If you're just trying to get a print out of each line of Perl code as it executes, the way that sh -x provides for shell scripts, you can't use Perl's -D switch. Instead do this. If -e is given, Perl will not look for a filename in the argument list. Multiple -e commands may be given to build up a multi-line script.
Make sure to use semicolons where you would in a normal program. See feature. This is a hook that allows the sysadmin to customize how Perl behaves. It can for instance be used to add entries to the INC array to make Perl find modules in non-standard locations. Since it is an actual do not a require , sitecustomize. The code is run in package main , in its own lexical scope. The code is executed very early. Of course, END blocks will be likewise executed very late.
You can't use literal whitespace or NUL characters in the pattern. It does this by renaming the input file, opening the output file by the original name, and selecting that output file as the default for print statements. The extension, if supplied, is used to modify the name of the old file to make a backup copy, following these rules:. If no extension is supplied, and your system supports it, the original file is kept open without a name while the output is redirected to a new file with the original filename.
When perl exits, cleanly or not, the original file is unlinked. In Perl terms, you could think of this as:. Or even to place backup copies of the original files into another directory provided the directory already exists :. Perl's -n switch allows you to run a program usually specified with -e against every line on standard input.
These are equivalent:. If you combine the -i switch, Perl will edit your file in place. Perl's -M switch allows you to use a module from the command line. It's also a convenient shortcut with -e if you need to include a module:. Try to load the module from the command line. The -e1 is just an empty program that exits immediately. The Perl program printed out "3", just like we expected. If we don't want to type "perl" in order to run the script, we can put this line:.
Then we type. Of course, we can use Perl to do more useful things. For example, we can look at all the files in the current directory. Here we use the opendir function to open a directory for reading. Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. Is there a Perl module that works similarly to the Unix "which" command? Asked 12 years, 3 months ago. Active 9 months ago.
0コメント