home *** CD-ROM | disk | FTP | other *** search
GNU Info File | 1994-07-08 | 32.2 KB | 730 lines |
- This is Info file perl.info, produced by Makeinfo-1.55 from the input
- file perltexi.
-
- This file documents perl, Practical Extraction and Report Language,
- and was originally based on Larry Wall's unix-style man page for perl.
-
- GNU Texinfo version adapted by Jeff Kellem
- <composer@Beyond.Dreams.ORG>.
-
- Copyright (C) 1989, 1990, 1991, 1992, 1993 Larry Wall Texinfo
- version Copyright (C) 1990, 1991, 1993 Jeff Kellem
-
- Permission is granted to make and distribute verbatim copies of this
- manual provided the copyright notice and this permission notice are
- preserved on all copies.
-
- Permission is granted to copy and distribute modified versions of
- this manual under the conditions for verbatim copying, provided also
- that the sections entitled "GNU General Public License" and "Conditions
- for Using Perl" are included exactly as in the original, and provided
- that the entire resulting derived work is distributed under the terms
- of a permission notice identical to this one.
-
- Permission is granted to copy and distribute translations of this
- manual into another language, under the above conditions for modified
- versions, except that the section entitled "GNU General Public License"
- and this permission notice may be included in translations approved by
- the Free Software Foundation instead of in the original English.
-
- File: perl.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
-
- This Info file contains edition 0.6, dated 13 September 1993,
- "printed" on 8 July 1994 of the Perl Manual for Perl version 4.0
- patchlevel 36.
-
- This is a *DRAFT* copy of the Texinfo version of the perl manual!
-
- * Menu:
-
- * Introduction:: A quick introduction to the manual.
- * Copying:: The GNU General Public License says how you can
- copy and share Perl.
- * Conditions:: Conditions for Using Perl. (Larry Wall's interpretation
- of the GPL and how it affects perl scripts.)
-
- * Preface:: A quick description of perl. (The hype.)
- * Perl Startup:: Where perl looks for scripts; perl's options.
- * Data Types:: Perl's data types and objects.
- * Syntax:: Perl language syntax.
- * Compound Statements:: What is a compound statement in Perl?
- * Simple Statements:: What is a simple statement in Perl?
- * Expressions:: What are valid expressions in Perl?
- * Commands:: All of perl's functions.
- * Precedence:: Operator precedence in Perl.
- * Subroutines:: Defining subroutines in Perl.
- * Passing By Reference:: How to pass args by reference in Perl.
- * Regular Expressions:: Perl's pattern matching capabilities.
- * Formats:: Report formats.
- * Interprocess Communication:: Networking in Perl.
- * Predefined Names:: Predefined variables.
- * Packages:: What is a Perl package? Find out here.
- * Style:: Suggestions on programming style.
- * Debugging:: The Perl debugger.
- * Setuid Scripts:: Setuid Perl scripts.
- * Environment:: Environment variables Perl utilizes.
- * a2p:: Awk to Perl conversion program.
- * s2p:: Sed to Perl conversion program.
- * h2ph:: Converting C header files into Perl header files.
- * Diagnostics:: What do the error messages mean?
- * Traps:: Traps and Pitfalls for C, sh, sed, awk programmers.
- * Bugs:: Known problems in Perl.
- (Mainly dependent upon your machine.)
- * Credits:: The Credits. Who worked on what.
- * Errata:: Errata and Addenda.
-
-
- * Command Summary:: Summary of commands (syntax only).
-
- Indices
- * Concept Index:: (mega ;-)Index of Concepts.
- * Function Index:: Index of Commands/Functions.
-
- File: perl.info, Node: Introduction, Next: Copying, Prev: Top, Up: Top
-
- Introduction
- ************
-
- This Texinfo manual describes PERL, the Practical Extraction and
- Report Language. The manual is, currently, mainly a conversion of Larry
- Wall's original unix-style man page into Texinfo format. In the
- future, new sections will be added, such as tutorial sections and more
- examples.
-
- The Texinfo version of the perl manual is maintained and distributed
- by Jeff Kellem. His electronic mail address is
- composer@Beyond.Dreams.ORG. There is a mailing list for discussion of
- the Texinfo version of the perl manual and a mailing address for
- reporting bugs in this version of the manual. They are:
-
- *Mailing Address* *What The Address Is For*
- perl-manual-request@Beyond.Dreams.ORG administrivia (add/drop requests)
- perl-manual@Beyond.Dreams.ORG discussion of the Texinfo perl manual
- bug-perl-manual@Beyond.Dreams.ORG reporting bugs in the perl manual
-
- If you would like to join the discussion of the perl manual, send a
- note to
-
- perl-manual-request@Beyond.Dreams.ORG
-
- The latest edition of the Texinfo version of the Perl manual is
- available via anonymous ftp from:
-
- ftp.dreams.org
-
- in the
-
- /pub/perl-manual
-
- directory.
-
- File: perl.info, Node: Copying, Next: Conditions, Prev: Introduction, Up: Top
-
- GNU General Public License
- **************************
-
- Version 1, February 1989
-
- Copyright (C) 1989 Free Software Foundation, Inc.
- 675 Mass Ave, Cambridge, MA 02139, USA
-
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
- ========
-
- The license agreements of most software companies try to keep users
- at the mercy of those companies. By contrast, our General Public
- License is intended to guarantee your freedom to share and change free
- software--to make sure the software is free for all its users. The
- General Public License applies to the Free Software Foundation's
- software and to any other program whose authors commit to using it.
- You can use it for your programs, too.
-
- When we speak of free software, we are referring to freedom, not
- price. Specifically, the General Public License is designed to make
- sure that you have the freedom to give away or sell copies of free
- software, that you receive source code or can get it if you want it,
- that you can change the software or use pieces of it in new free
- programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
- anyone to deny you these rights or to ask you to surrender the rights.
- These restrictions translate to certain responsibilities for you if you
- distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of a such a program, whether
- gratis or for a fee, you must give the recipients all the rights that
- you have. You must make sure that they, too, receive or can get the
- source code. And you must tell them their rights.
-
- We protect your rights with two steps: (1) copyright the software,
- and (2) offer you this license which gives you legal permission to copy,
- distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
- that everyone understands that there is no warranty for this free
- software. If the software is modified by someone else and passed on, we
- want its recipients to know that what they have is not the original, so
- that any problems introduced by others will not reflect on the original
- authors' reputations.
-
- The precise terms and conditions for copying, distribution and
- modification follow.
-
- TERMS AND CONDITIONS
-
- 1. This License Agreement applies to any program or other work which
- contains a notice placed by the copyright holder saying it may be
- distributed under the terms of this General Public License. The
- "Program", below, refers to any such program or work, and a "work
- based on the Program" means either the Program or any work
- containing the Program or a portion of it, either verbatim or with
- modifications. Each licensee is addressed as "you".
-
- 2. You may copy and distribute verbatim copies of the Program's source
- code as you receive it, in any medium, provided that you
- conspicuously and appropriately publish on each copy an
- appropriate copyright notice and disclaimer of warranty; keep
- intact all the notices that refer to this General Public License
- and to the absence of any warranty; and give any other recipients
- of the Program a copy of this General Public License along with
- the Program. You may charge a fee for the physical act of
- transferring a copy.
-
- 3. You may modify your copy or copies of the Program or any portion of
- it, and copy and distribute such modifications under the terms of
- Paragraph 1 above, provided that you also do the following:
-
- * cause the modified files to carry prominent notices stating
- that you changed the files and the date of any change; and
-
- * cause the whole of any work that you distribute or publish,
- that in whole or in part contains the Program or any part
- thereof, either with or without modifications, to be licensed
- at no charge to all third parties under the terms of this
- General Public License (except that you may choose to grant
- warranty protection to some or all third parties, at your
- option).
-
- * If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the simplest and most usual way, to print
- or display an announcement including an appropriate copyright
- notice and a notice that there is no warranty (or else,
- saying that you provide a warranty) and that users may
- redistribute the program under these conditions, and telling
- the user how to view a copy of this General Public License.
-
- * You may charge a fee for the physical act of transferring a
- copy, and you may at your option offer warranty protection in
- exchange for a fee.
-
- Mere aggregation of another independent work with the Program (or
- its derivative) on a volume of a storage or distribution medium
- does not bring the other work under the scope of these terms.
-
- 4. You may copy and distribute the Program (or a portion or
- derivative of it, under Paragraph 2) in object code or executable
- form under the terms of Paragraphs 1 and 2 above provided that you
- also do one of the following:
-
- * accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of
- Paragraphs 1 and 2 above; or,
-
- * accompany it with a written offer, valid for at least three
- years, to give any third party free (except for a nominal
- charge for the cost of distribution) a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Paragraphs 1 and 2 above; or,
-
- * accompany it with the information you received as to where the
- corresponding source code may be obtained. (This alternative
- is allowed only for noncommercial distribution and only if you
- received the program in object code or executable form alone.)
-
- Source code for a work means the preferred form of the work for
- making modifications to it. For an executable file, complete
- source code means all the source code for all modules it contains;
- but, as a special exception, it need not include source code for
- modules which are standard libraries that accompany the operating
- system on which the executable file runs, or for standard header
- files or definitions files that accompany that operating system.
-
- 5. You may not copy, modify, sublicense, distribute or transfer the
- Program except as expressly provided under this General Public
- License. Any attempt otherwise to copy, modify, sublicense,
- distribute or transfer the Program is void, and will automatically
- terminate your rights to use the Program under this License.
- However, parties who have received copies, or rights to use
- copies, from you under this General Public License will not have
- their licenses terminated so long as such parties remain in full
- compliance.
-
- 6. By copying, distributing or modifying the Program (or any work
- based on the Program) you indicate your acceptance of this license
- to do so, and all its terms and conditions.
-
- 7. Each time you redistribute the Program (or any work based on the
- Program), the recipient automatically receives a license from the
- original licensor to copy, distribute or modify the Program
- subject to these terms and conditions. You may not impose any
- further restrictions on the recipients' exercise of the rights
- granted herein.
-
- 8. The Free Software Foundation may publish revised and/or new
- versions of the General Public License from time to time. Such
- new versions will be similar in spirit to the present version, but
- may differ in detail to address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
- Program specifies a version number of the license which applies to
- it and "any later version", you have the option of following the
- terms and conditions either of that version or of any later
- version published by the Free Software Foundation. If the Program
- does not specify a version number of the license, you may choose
- any version ever published by the Free Software Foundation.
-
- 9. If you wish to incorporate parts of the Program into other free
- programs whose distribution conditions are different, write to the
- author to ask for permission. For software which is copyrighted
- by the Free Software Foundation, write to the Free Software
- Foundation; we sometimes make exceptions for this. Our decision
- will be guided by the two goals of preserving the free status of
- all derivatives of our free software and of promoting the sharing
- and reuse of software generally.
-
- NO WARRANTY
-
- 10. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
- WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
- LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
- HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
- WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
- NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
- QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
- PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
- SERVICING, REPAIR OR CORRECTION.
-
- 11. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
- WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
- MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
- LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
- INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
- INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
- DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
- OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
- OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- Appendix: How to Apply These Terms
- ==================================
-
- If you develop a new program, and you want it to be of the greatest
- possible use to humanity, the best way to achieve this is to make it
- free software which everyone can redistribute and change under these
- terms.
-
- To do so, attach the following notices to the program. It is safest
- to attach them to the start of each source file to most effectively
- convey the exclusion of warranty; and each file should have at least the
- "copyright" line and a pointer to where the full notice is found.
-
- ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
- Copyright (C) 19YY NAME OF AUTHOR
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Also add information on how to contact you by electronic and paper mail.
-
- If the program is interactive, make it output a short notice like
- this when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
- The hypothetical commands `show w' and `show c' should show the
- appropriate parts of the General Public License. Of course, the
- commands you use may be called something other than `show w' and `show
- c'; they could even be mouse-clicks or menu items--whatever suits your
- program.
-
- You should also get your employer (if you work as a programmer) or
- your school, if any, to sign a "copyright disclaimer" for the program,
- if necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (a program to direct compilers to make passes at
- assemblers) written by James Hacker.
-
- SIGNATURE OF TY COON, 1 April 1989
- Ty Coon, President of Vice
-
- That's all there is to it!
-
- File: perl.info, Node: Conditions, Next: Preface, Prev: Copying, Up: Top
-
- Conditions for Using Perl
- *************************
-
- [ Note: The following is from the author of Perl, Larry Wall. ]
-
- My interpretation of the GNU General Public License is that no Perl
- script falls under the terms of the License unless you explicitly put
- said script under the terms of the License yourself. Furthermore, any
- object code linked with uperl.o does not automatically fall under the
- terms of the License, provided such object code only adds definitions
- of subroutines and variables, and does not otherwise impair the
- resulting interpreter from executing any standard Perl script. I
- consider linking in C subroutines in this manner to be the moral
- equivalent of defining subroutines in the Perl language itself. You
- may sell such an object file as proprietary provided that you provide
- or offer to provide the Perl source, as specified by the GNU General
- Public License. (This is merely an alternate way of specifying input
- to the program.) You may also sell a binary produced by the dumping of
- a running Perl script that belongs to you, provided that you provide or
- offer to provide the Perl source as specified by the License. (The
- fact that a Perl interpreter and your code are in the same binary file
- is, in this case, a form of mere aggregation.) This is my
- interpretation of the License. If you still have concerns or
- difficulties understanding my intent, feel free to contact me.
-
- File: perl.info, Node: Preface, Next: Perl Startup, Prev: Conditions, Up: Top
-
- Description
- ***********
-
- "Perl" is an interpreted language optimized for scanning arbitrary
- text files, extracting information from those text files, and printing
- reports based on that information. It's also a good language for many
- system management tasks. The language is intended to be practical (easy
- to use, efficient, complete) rather than beautiful (tiny, elegant,
- minimal). It combines (in the author's opinion, anyway) some of the
- best features of `C', `sed', `awk', and `sh', so people familiar with
- those languages should have little difficulty with it. (Language
- historians will also note some vestiges of `csh', `Pascal', and even
- `BASIC-PLUS'.) Expression syntax corresponds quite closely to C
- expression syntax. Unlike most Unix utilities, *perl* does not
- arbitrarily limit the size of your data--if you've got the memory,
- *perl* can slurp in your whole file as a single string. Recursion is
- of unlimited depth. And the hash tables used by associative arrays
- grow as necessary to prevent degraded performance. *Perl* uses
- sophisticated pattern matching techniques to scan large amounts of data
- very quickly. Although optimized for scanning text, *perl* can also
- deal with binary data, and can make dbm files look like associative
- arrays (where dbm is available). Setuid *perl* scripts are safer than
- C programs through a dataflow tracing mechanism which prevents many
- stupid security holes. If you have a problem that would ordinarily use
- `sed' or `awk' or `sh', but it exceeds their capabilities or must run a
- little faster, and you don't want to write the silly thing in C, then
- *perl* may be for you. There are also translators to turn your `sed'
- and `awk' scripts into *perl* scripts. OK, enough hype.
-
- File: perl.info, Node: Perl Startup, Next: Data Types, Prev: Preface, Up: Top
-
- Perl Startup
- ************
-
- Upon startup, *perl* looks for your script in one of the following
- places:
-
- 1. Specified line by line via `-e' switches on the command line.
-
- 2. Contained in the file specified by the first filename on the
- command line. (Note that systems supporting the `#!' notation
- invoke interpreters this way.)
-
- 3. Passed in implicitly via standard input. This only works if there
- are no filename arguments--to pass arguments to a `stdin' script
- you must explicitly specify a `-' for the script name.
-
- After locating your script, *perl* compiles it to an internal form.
- If the script is syntactically correct, it is executed.
-
- * Menu:
-
- * Options:: Command line options.
-
- File: perl.info, Node: Options, Up: Perl Startup
-
- Options
- =======
-
- Note: on first reading this section may not make much sense to you.
- It's here at the front for easy reference.
-
- A single-character option may be combined with the following option,
- if any. This is particularly useful when invoking a script using the
- `#!' construct which only allows one argument. Example:
-
- #!/usr/bin/perl -spi.bak # same as -s -p -i.bak
- ...
-
- Options include:
-
- `-0 digits'
- specifies the record separator ($/) as an octal number. 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:
-
- find . -name '*.bak' -print0 | perl -n0e unlink
-
- The special value `00' will cause Perl to slurp files in paragraph
- mode. The value `0777' will cause Perl to slurp files whole since
- there is no legal character with that value.
-
- `-a'
- turns on autosplit mode when used with a `-n' or `-p'. 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'.
-
- perl -ane 'print pop(@F), "\n";'
-
- is equivalent to
-
- while (<>) {
- @F = split(' ');
- print pop(@F), "\n";
- }
-
- `-c'
- causes *perl* to check the syntax of the script and then exit
- without executing it.
-
- `-d'
- runs the script under the perl debugger. *Note Debugging::, for
- more info.
-
- `-D number'
- sets debugging flags. To watch how it executes your script, use
- `-D14'. (This only works if debugging is compiled into your
- *perl*.) Another nice value is `-D1024', which lists your
- compiled syntax tree. And `-D512' displays compiled regular
- expressions.
-
- `-e commandline'
- may be used to enter one line of script. Multiple `-e' commands
- may be given to build up a multi-line script. If `-e' is given,
- *perl* will not look for a script filename in the argument list.
-
- `-i extension'
- specifies that files processed by the `<>' construct are to be
- edited in-place. It does this by renaming the input file, opening
- the output file by the same name, and selecting that output file
- as the default for print statements. The extension, if supplied,
- is added to the name of the old file to make a backup copy. If no
- extension is supplied, no backup is made. Saying
-
- perl -p -i.bak -e "s/foo/bar/;" ...
-
- is the same as using the script:
-
- #!/usr/bin/perl -pi.bak
- s/foo/bar/;
-
- which is equivalent to
-
- #!/usr/bin/perl
- while (<>) {
- if ($ARGV ne $oldargv) {
- rename($ARGV, $ARGV . '.bak');
- open(ARGVOUT, ">$ARGV");
- select(ARGVOUT);
- $oldargv = $ARGV;
- }
- s/foo/bar/;
- }
- continue {
- print; # this prints to original filename
- }
- select(STDOUT);
-
- except that the `-i' form doesn't need to compare `$ARGV' to
- `$oldargv' to know when the filename has changed. It does,
- however, use `ARGVOUT' for the selected filehandle. Note that
- `STDOUT' is restored as the default output filehandle after the
- loop.
-
- You can use `eof' to locate the end of each input file, in case you
- want to append to each file, or reset line numbering (*note
- Input/Output::., for an example).
-
- `-I directory'
- may be used in conjunction with `-P' to tell the C preprocessor
- where to look for include files. By default `/usr/include' and
- `/usr/lib/perl' are searched.
-
- `-l octnum'
- enables automatic line-ending processing. It has two effects:
- first, it automatically chops the line terminator when used with
- `-n' or `-p', and second, it assigns `$\' to have the value of
- OCTNUM so that any print statements will have that line terminator
- added back on. If OCTNUM is omitted, sets `$\' to the current
- value of `$/'. For instance, to trim lines to 80 columns:
-
- perl -lpe 'substr($_, 80) = ""'
-
- Note that the assignment `$\ = $/' is done when the switch is
- processed, so the input record separator can be different than the
- output record separator if the `-l' switch is followed by a `-0'
- switch:
-
- gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
-
- This sets `$\' to newline and then sets `$/' to the null character.
-
- `-n'
- causes *perl* to assume the following loop around your script,
- which makes it iterate over filename arguments somewhat like `sed
- -n' or `awk':
-
- while (<>) {
- ... # your script goes here
- }
-
- Note that the lines are *not* printed by default. See `-p' option
- to have lines printed. Here is an efficient way to delete all
- files older than a week:
-
- [ before version 4.003 ]
- find . -mtime +7 -print | perl -ne 'chop;unlink;'
-
- [ version 4.003 and beyond ]
- find . -mtime +7 -print | perl -nle 'unlink;'
-
- This is faster than using the `-exec' switch of find because you
- don't have to start a process on every filename found.
-
- `-p'
- causes *perl* to assume the following loop around your script,
- which makes it iterate over filename arguments somewhat like `sed':
-
- while (<>) {
- ... # your script goes here
- } continue {
- print;
- }
-
- Note that the lines are printed automatically. To suppress
- printing use the `-n' switch. A `-p' overrides a `-n' switch.
-
- `-P'
- causes your script to be run through the C preprocessor before
- compilation by *perl*. (Since both comments and cpp directives
- begin with the `#' character, you should avoid starting comments
- with any words recognized by the C preprocessor such as `if',
- `else' or `define'.)
-
- `-s'
- enables some rudimentary switch parsing for switches on the
- command line after the script name but before any filename
- arguments (or before a `--'). Any switch found there is removed
- from `@ARGV' and sets the corresponding variable in the *perl*
- script. The following script prints `true' if and only if the
- script is invoked with a `-xyz' switch.
-
- #!/usr/bin/perl -s
- if ($xyz) { print "true\n"; }
-
- `-S'
- makes *perl* use the `PATH' environment variable to search for the
- script (unless the name of the script starts with a slash).
- Typically this is used to emulate `#!' startup on machines that
- don't support `#!', in the following manner:
-
- #!/usr/bin/perl
- eval "exec /usr/bin/perl -S $0 $*"
- if $running_under_some_shell;
-
- The system ignores the first line and feeds the script to
- `/bin/sh', which proceeds to try to execute the *perl* script as a
- shell script. The shell executes the second line as a normal shell
- command, and thus starts up the *perl* interpreter. On some
- systems `$0' doesn't always contain the full pathname, so the `-S'
- tells *perl* to search for the script if necessary. After *perl*
- locates the script, it parses the lines and ignores them because
- the variable `$running_under_some_shell' is never true. A better
- construct than `$*' would be `${1+"$@"}', which handles embedded
- spaces and such in the filenames, but doesn't work if the script
- is being interpreted by `csh'. In order to start up `sh' rather
- than `csh', some systems may have to replace the `#!' line with a
- line containing just a colon, which will be politely ignored by
- *perl*. Other systems can't control that, and need a totally
- devious construct that will work under any of `csh', `sh' or
- `perl', such as the following:
-
- eval '(exit $?0)' && eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
- & eval 'exec /usr/bin/perl -S $0 $argv:q'
- if 0;
-
- `-u'
- causes *perl* to dump core after compiling your script. You can
- then take this core dump and turn it into an executable file by
- using the `undump' program (not supplied). This speeds startup at
- the expense of some disk space (which you can minimize by
- stripping the executable). (Still, a "hello world" executable
- comes out to about 200K on my machine.) If you are going to run
- your executable as a set-id program then you should probably
- compile it using taintperl rather than normal perl. If you want
- to execute a portion of your script before dumping, use the `dump'
- operator instead. Note: availability of `undump' is platform
- specific and may not be available for a specific port of *perl*.
-
- `-U'
- allows *perl* to do unsafe operations. Currently the only
- `unsafe' operations are the unlinking of directories while running
- as superuser, and running setuid programs with fatal taint checks
- turned into warnings.
-
- `-v'
- prints the version and patchlevel of your *perl* executable.
-
- `-w'
- prints warnings about identifiers that are mentioned only once, and
- scalar variables that are used before being set. Also warns about
- redefined subroutines, and references to undefined filehandles or
- filehandles opened readonly that you are attempting to write on.
- Also warns you if you use `==' on values that don't look like
- numbers, and if your subroutines recurse more than 100 deep.
-
- `-x directory'
- tells *perl* that the script is embedded in a message. Leading
- garbage will be discarded until the first line that starts with
- `#!' and contains the string "perl". Any meaningful switches on
- that line will be applied (but only one group of switches, as with
- normal `#!' processing). If a directory name is specified, *perl*
- will switch to that directory before running the script. The `-x'
- switch only controls the the disposal of leading garbage. The
- script must be terminated with `__END__' if there is trailing
- garbage to be ignored (the script can process any or all of the
- trailing garbage via the `DATA' filehandle if desired).
-
-