home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / PERL / PERL-4.036 / PERL-4 / perl-4.036 / Info / perl.info-1 next >
Encoding:
GNU Info File  |  1994-07-08  |  32.2 KB  |  730 lines

  1. This is Info file perl.info, produced by Makeinfo-1.55 from the input
  2. file perltexi.
  3.  
  4.    This file documents perl, Practical Extraction and Report Language,
  5. and was originally based on Larry Wall's unix-style man page for perl.
  6.  
  7.    GNU Texinfo version adapted by Jeff Kellem
  8. <composer@Beyond.Dreams.ORG>.
  9.  
  10.    Copyright (C) 1989, 1990, 1991, 1992, 1993 Larry Wall Texinfo
  11. version Copyright (C) 1990, 1991, 1993 Jeff Kellem
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided also
  19. that the sections entitled "GNU General Public License" and "Conditions
  20. for Using Perl" are included exactly as in the original, and provided
  21. that the entire resulting derived work is distributed under the terms
  22. of a permission notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions, except that the section entitled "GNU General Public License"
  27. and this permission notice may be included in translations approved by
  28. the Free Software Foundation instead of in the original English.
  29.  
  30. 
  31. File: perl.info,  Node: Top,  Next: Introduction,  Prev: (dir),  Up: (dir)
  32.  
  33.    This Info file contains edition 0.6, dated 13 September 1993,
  34. "printed" on 8 July 1994 of the Perl Manual for Perl version 4.0
  35. patchlevel 36.
  36.  
  37.    This is a *DRAFT* copy of the Texinfo version of the perl manual!
  38.  
  39. * Menu:
  40.  
  41. * Introduction::        A quick introduction to the manual.
  42. * Copying::             The GNU General Public License says how you can
  43.                           copy and share Perl.
  44. * Conditions::          Conditions for Using Perl. (Larry Wall's interpretation
  45.                           of the GPL and how it affects perl scripts.)
  46.  
  47. * Preface::               A quick description of perl.  (The hype.)
  48. * Perl Startup::          Where perl looks for scripts; perl's options.
  49. * Data Types::            Perl's data types and objects.
  50. * Syntax::                Perl language syntax.
  51. * Compound Statements::   What is a compound statement in Perl?
  52. * Simple Statements::     What is a simple statement in Perl?
  53. * Expressions::           What are valid expressions in Perl?
  54. * Commands::              All of perl's functions.
  55. * Precedence::            Operator precedence in Perl.
  56. * Subroutines::           Defining subroutines in Perl.
  57. * Passing By Reference::  How to pass args by reference in Perl.
  58. * Regular Expressions::   Perl's pattern matching capabilities.
  59. * Formats::               Report formats.
  60. * Interprocess Communication:: Networking in Perl.
  61. * Predefined Names::      Predefined variables.
  62. * Packages::              What is a Perl package?  Find out here.
  63. * Style::                 Suggestions on programming style.
  64. * Debugging::             The Perl debugger.
  65. * Setuid Scripts::        Setuid Perl scripts.
  66. * Environment::           Environment variables Perl utilizes.
  67. * a2p::                   Awk to Perl conversion program.
  68. * s2p::                   Sed to Perl conversion program.
  69. * h2ph::                  Converting C header files into Perl header files.
  70. * Diagnostics::           What do the error messages mean?
  71. * Traps::                 Traps and Pitfalls for C, sh, sed, awk programmers.
  72. * Bugs::                  Known problems in Perl.
  73.                             (Mainly dependent upon your machine.)
  74. * Credits::               The Credits.  Who worked on what.
  75. * Errata::                Errata and Addenda.
  76.  
  77.  
  78. * Command Summary::     Summary of commands (syntax only).
  79.  
  80. Indices
  81. * Concept Index::       (mega ;-)Index of Concepts.
  82. * Function Index::      Index of Commands/Functions.
  83.  
  84. 
  85. File: perl.info,  Node: Introduction,  Next: Copying,  Prev: Top,  Up: Top
  86.  
  87. Introduction
  88. ************
  89.  
  90.    This Texinfo manual describes PERL, the Practical Extraction and
  91. Report Language.  The manual is, currently, mainly a conversion of Larry
  92. Wall's original unix-style man page into Texinfo format.  In the
  93. future, new sections will be added, such as tutorial sections and more
  94. examples.
  95.  
  96.    The Texinfo version of the perl manual is maintained and distributed
  97. by Jeff Kellem.  His electronic mail address is
  98. composer@Beyond.Dreams.ORG.  There is a mailing list for discussion of
  99. the Texinfo version of the perl manual and a mailing address for
  100. reporting bugs in this version of the manual.  They are:
  101.  
  102.      *Mailing Address*                           *What The Address Is For*
  103.      perl-manual-request@Beyond.Dreams.ORG    administrivia (add/drop requests)
  104.      perl-manual@Beyond.Dreams.ORG            discussion of the Texinfo perl manual
  105.      bug-perl-manual@Beyond.Dreams.ORG        reporting bugs in the perl manual
  106.  
  107. If you would like to join the discussion of the perl manual, send a
  108. note to
  109.  
  110.      perl-manual-request@Beyond.Dreams.ORG
  111.  
  112. The latest edition of the Texinfo version of the Perl manual is
  113. available via anonymous ftp from:
  114.  
  115.      ftp.dreams.org
  116.  
  117. in the
  118.  
  119.      /pub/perl-manual
  120.  
  121. directory.
  122.  
  123. 
  124. File: perl.info,  Node: Copying,  Next: Conditions,  Prev: Introduction,  Up: Top
  125.  
  126. GNU General Public License
  127. **************************
  128.  
  129.                        Version 1, February 1989
  130.  
  131.      Copyright (C) 1989 Free Software Foundation, Inc.
  132.      675 Mass Ave, Cambridge, MA 02139, USA
  133.      
  134.      Everyone is permitted to copy and distribute verbatim copies
  135.      of this license document, but changing it is not allowed.
  136.  
  137. Preamble
  138. ========
  139.  
  140.    The license agreements of most software companies try to keep users
  141. at the mercy of those companies.  By contrast, our General Public
  142. License is intended to guarantee your freedom to share and change free
  143. software--to make sure the software is free for all its users.  The
  144. General Public License applies to the Free Software Foundation's
  145. software and to any other program whose authors commit to using it.
  146. You can use it for your programs, too.
  147.  
  148.    When we speak of free software, we are referring to freedom, not
  149. price.  Specifically, the General Public License is designed to make
  150. sure that you have the freedom to give away or sell copies of free
  151. software, that you receive source code or can get it if you want it,
  152. that you can change the software or use pieces of it in new free
  153. programs; and that you know you can do these things.
  154.  
  155.    To protect your rights, we need to make restrictions that forbid
  156. anyone to deny you these rights or to ask you to surrender the rights.
  157. These restrictions translate to certain responsibilities for you if you
  158. distribute copies of the software, or if you modify it.
  159.  
  160.    For example, if you distribute copies of a such a program, whether
  161. gratis or for a fee, you must give the recipients all the rights that
  162. you have.  You must make sure that they, too, receive or can get the
  163. source code.  And you must tell them their rights.
  164.  
  165.    We protect your rights with two steps: (1) copyright the software,
  166. and (2) offer you this license which gives you legal permission to copy,
  167. distribute and/or modify the software.
  168.  
  169.    Also, for each author's protection and ours, we want to make certain
  170. that everyone understands that there is no warranty for this free
  171. software.  If the software is modified by someone else and passed on, we
  172. want its recipients to know that what they have is not the original, so
  173. that any problems introduced by others will not reflect on the original
  174. authors' reputations.
  175.  
  176.    The precise terms and conditions for copying, distribution and
  177. modification follow.
  178.  
  179.                          TERMS AND CONDITIONS
  180.  
  181.   1. This License Agreement applies to any program or other work which
  182.      contains a notice placed by the copyright holder saying it may be
  183.      distributed under the terms of this General Public License.  The
  184.      "Program", below, refers to any such program or work, and a "work
  185.      based on the Program" means either the Program or any work
  186.      containing the Program or a portion of it, either verbatim or with
  187.      modifications.  Each licensee is addressed as "you".
  188.  
  189.   2. You may copy and distribute verbatim copies of the Program's source
  190.      code as you receive it, in any medium, provided that you
  191.      conspicuously and appropriately publish on each copy an
  192.      appropriate copyright notice and disclaimer of warranty; keep
  193.      intact all the notices that refer to this General Public License
  194.      and to the absence of any warranty; and give any other recipients
  195.      of the Program a copy of this General Public License along with
  196.      the Program.  You may charge a fee for the physical act of
  197.      transferring a copy.
  198.  
  199.   3. You may modify your copy or copies of the Program or any portion of
  200.      it, and copy and distribute such modifications under the terms of
  201.      Paragraph 1 above, provided that you also do the following:
  202.  
  203.         * cause the modified files to carry prominent notices stating
  204.           that you changed the files and the date of any change; and
  205.  
  206.         * cause the whole of any work that you distribute or publish,
  207.           that in whole or in part contains the Program or any part
  208.           thereof, either with or without modifications, to be licensed
  209.           at no charge to all third parties under the terms of this
  210.           General Public License (except that you may choose to grant
  211.           warranty protection to some or all third parties, at your
  212.           option).
  213.  
  214.         * If the modified program normally reads commands interactively
  215.           when run, you must cause it, when started running for such
  216.           interactive use in the simplest and most usual way, to print
  217.           or display an announcement including an appropriate copyright
  218.           notice and a notice that there is no warranty (or else,
  219.           saying that you provide a warranty) and that users may
  220.           redistribute the program under these conditions, and telling
  221.           the user how to view a copy of this General Public License.
  222.  
  223.         * You may charge a fee for the physical act of transferring a
  224.           copy, and you may at your option offer warranty protection in
  225.           exchange for a fee.
  226.  
  227.      Mere aggregation of another independent work with the Program (or
  228.      its derivative) on a volume of a storage or distribution medium
  229.      does not bring the other work under the scope of these terms.
  230.  
  231.   4. You may copy and distribute the Program (or a portion or
  232.      derivative of it, under Paragraph 2) in object code or executable
  233.      form under the terms of Paragraphs 1 and 2 above provided that you
  234.      also do one of the following:
  235.  
  236.         * accompany it with the complete corresponding machine-readable
  237.           source code, which must be distributed under the terms of
  238.           Paragraphs 1 and 2 above; or,
  239.  
  240.         * accompany it with a written offer, valid for at least three
  241.           years, to give any third party free (except for a nominal
  242.           charge for the cost of distribution) a complete
  243.           machine-readable copy of the corresponding source code, to be
  244.           distributed under the terms of Paragraphs 1 and 2 above; or,
  245.  
  246.         * accompany it with the information you received as to where the
  247.           corresponding source code may be obtained.  (This alternative
  248.           is allowed only for noncommercial distribution and only if you
  249.           received the program in object code or executable form alone.)
  250.  
  251.      Source code for a work means the preferred form of the work for
  252.      making modifications to it.  For an executable file, complete
  253.      source code means all the source code for all modules it contains;
  254.      but, as a special exception, it need not include source code for
  255.      modules which are standard libraries that accompany the operating
  256.      system on which the executable file runs, or for standard header
  257.      files or definitions files that accompany that operating system.
  258.  
  259.   5. You may not copy, modify, sublicense, distribute or transfer the
  260.      Program except as expressly provided under this General Public
  261.      License.  Any attempt otherwise to copy, modify, sublicense,
  262.      distribute or transfer the Program is void, and will automatically
  263.      terminate your rights to use the Program under this License.
  264.      However, parties who have received copies, or rights to use
  265.      copies, from you under this General Public License will not have
  266.      their licenses terminated so long as such parties remain in full
  267.      compliance.
  268.  
  269.   6. By copying, distributing or modifying the Program (or any work
  270.      based on the Program) you indicate your acceptance of this license
  271.      to do so, and all its terms and conditions.
  272.  
  273.   7. Each time you redistribute the Program (or any work based on the
  274.      Program), the recipient automatically receives a license from the
  275.      original licensor to copy, distribute or modify the Program
  276.      subject to these terms and conditions.  You may not impose any
  277.      further restrictions on the recipients' exercise of the rights
  278.      granted herein.
  279.  
  280.   8. The Free Software Foundation may publish revised and/or new
  281.      versions of the General Public License from time to time.  Such
  282.      new versions will be similar in spirit to the present version, but
  283.      may differ in detail to address new problems or concerns.
  284.  
  285.      Each version is given a distinguishing version number.  If the
  286.      Program specifies a version number of the license which applies to
  287.      it and "any later version", you have the option of following the
  288.      terms and conditions either of that version or of any later
  289.      version published by the Free Software Foundation.  If the Program
  290.      does not specify a version number of the license, you may choose
  291.      any version ever published by the Free Software Foundation.
  292.  
  293.   9. If you wish to incorporate parts of the Program into other free
  294.      programs whose distribution conditions are different, write to the
  295.      author to ask for permission.  For software which is copyrighted
  296.      by the Free Software Foundation, write to the Free Software
  297.      Foundation; we sometimes make exceptions for this.  Our decision
  298.      will be guided by the two goals of preserving the free status of
  299.      all derivatives of our free software and of promoting the sharing
  300.      and reuse of software generally.
  301.  
  302.                                 NO WARRANTY
  303.  
  304.  10. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
  305.      WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
  306.      LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  307.      HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
  308.      WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
  309.      NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  310.      FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
  311.      QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  312.      PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  313.      SERVICING, REPAIR OR CORRECTION.
  314.  
  315.  11. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  316.      WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
  317.      MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
  318.      LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  319.      INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  320.      INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  321.      DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
  322.      OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
  323.      OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  324.      ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  325.  
  326.                       END OF TERMS AND CONDITIONS
  327.  
  328. Appendix: How to Apply These Terms
  329. ==================================
  330.  
  331.    If you develop a new program, and you want it to be of the greatest
  332. possible use to humanity, the best way to achieve this is to make it
  333. free software which everyone can redistribute and change under these
  334. terms.
  335.  
  336.    To do so, attach the following notices to the program.  It is safest
  337. to attach them to the start of each source file to most effectively
  338. convey the exclusion of warranty; and each file should have at least the
  339. "copyright" line and a pointer to where the full notice is found.
  340.  
  341.      ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
  342.      Copyright (C) 19YY  NAME OF AUTHOR
  343.      
  344.      This program is free software; you can redistribute it and/or modify
  345.      it under the terms of the GNU General Public License as published by
  346.      the Free Software Foundation; either version 1, or (at your option)
  347.      any later version.
  348.      
  349.      This program is distributed in the hope that it will be useful,
  350.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  351.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  352.      GNU General Public License for more details.
  353.      
  354.      You should have received a copy of the GNU General Public License
  355.      along with this program; if not, write to the Free Software
  356.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  357.  
  358. Also add information on how to contact you by electronic and paper mail.
  359.  
  360.    If the program is interactive, make it output a short notice like
  361. this when it starts in an interactive mode:
  362.  
  363.      Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
  364.      Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  365.      This is free software, and you are welcome to redistribute it
  366.      under certain conditions; type `show c' for details.
  367.  
  368.    The hypothetical commands `show w' and `show c' should show the
  369. appropriate parts of the General Public License.  Of course, the
  370. commands you use may be called something other than `show w' and `show
  371. c'; they could even be mouse-clicks or menu items--whatever suits your
  372. program.
  373.  
  374.    You should also get your employer (if you work as a programmer) or
  375. your school, if any, to sign a "copyright disclaimer" for the program,
  376. if necessary.  Here is a sample; alter the names:
  377.  
  378.      Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  379.      `Gnomovision' (a program to direct compilers to make passes at
  380.      assemblers) written by James Hacker.
  381.      
  382.      SIGNATURE OF TY COON, 1 April 1989
  383.      Ty Coon, President of Vice
  384.  
  385. That's all there is to it!
  386.  
  387. 
  388. File: perl.info,  Node: Conditions,  Next: Preface,  Prev: Copying,  Up: Top
  389.  
  390. Conditions for Using Perl
  391. *************************
  392.  
  393. [ Note: The following is from the author of Perl, Larry Wall. ]
  394.  
  395.    My interpretation of the GNU General Public License is that no Perl
  396. script falls under the terms of the License unless you explicitly put
  397. said script under the terms of the License yourself.  Furthermore, any
  398. object code linked with uperl.o does not automatically fall under the
  399. terms of the License, provided such object code only adds definitions
  400. of subroutines and variables, and does not otherwise impair the
  401. resulting interpreter from executing any standard Perl script.  I
  402. consider linking in C subroutines in this manner to be the moral
  403. equivalent of defining subroutines in the Perl language itself.  You
  404. may sell such an object file as proprietary provided that you provide
  405. or offer to provide the Perl source, as specified by the GNU General
  406. Public License.  (This is merely an alternate way of specifying input
  407. to the program.)  You may also sell a binary produced by the dumping of
  408. a running Perl script that belongs to you, provided that you provide or
  409. offer to provide the Perl source as specified by the License.  (The
  410. fact that a Perl interpreter and your code are in the same binary file
  411. is, in this case, a form of mere aggregation.)  This is my
  412. interpretation of the License.  If you still have concerns or
  413. difficulties understanding my intent, feel free to contact me.
  414.  
  415. 
  416. File: perl.info,  Node: Preface,  Next: Perl Startup,  Prev: Conditions,  Up: Top
  417.  
  418. Description
  419. ***********
  420.  
  421.    "Perl" is an interpreted language optimized for scanning arbitrary
  422. text files, extracting information from those text files, and printing
  423. reports based on that information.  It's also a good language for many
  424. system management tasks.  The language is intended to be practical (easy
  425. to use, efficient, complete) rather than beautiful (tiny, elegant,
  426. minimal).  It combines (in the author's opinion, anyway) some of the
  427. best features of `C', `sed', `awk', and `sh', so people familiar with
  428. those languages should have little difficulty with it.  (Language
  429. historians will also note some vestiges of `csh', `Pascal', and even
  430. `BASIC-PLUS'.)  Expression syntax corresponds quite closely to C
  431. expression syntax.  Unlike most Unix utilities, *perl* does not
  432. arbitrarily limit the size of your data--if you've got the memory,
  433. *perl* can slurp in your whole file as a single string.  Recursion is
  434. of unlimited depth.  And the hash tables used by associative arrays
  435. grow as necessary to prevent degraded performance.  *Perl* uses
  436. sophisticated pattern matching techniques to scan large amounts of data
  437. very quickly.  Although optimized for scanning text, *perl* can also
  438. deal with binary data, and can make dbm files look like associative
  439. arrays (where dbm is available).  Setuid *perl* scripts are safer than
  440. C programs through a dataflow tracing mechanism which prevents many
  441. stupid security holes.  If you have a problem that would ordinarily use
  442. `sed' or `awk' or `sh', but it exceeds their capabilities or must run a
  443. little faster, and you don't want to write the silly thing in C, then
  444. *perl* may be for you.  There are also translators to turn your `sed'
  445. and `awk' scripts into *perl* scripts.  OK, enough hype.
  446.  
  447. 
  448. File: perl.info,  Node: Perl Startup,  Next: Data Types,  Prev: Preface,  Up: Top
  449.  
  450. Perl Startup
  451. ************
  452.  
  453. Upon startup, *perl* looks for your script in one of the following
  454. places:
  455.  
  456.   1. Specified line by line via `-e' switches on the command line.
  457.  
  458.   2. Contained in the file specified by the first filename on the
  459.      command line.  (Note that systems supporting the `#!' notation
  460.      invoke interpreters this way.)
  461.  
  462.   3. Passed in implicitly via standard input.  This only works if there
  463.      are no filename arguments--to pass arguments to a `stdin' script
  464.      you must explicitly specify a `-' for the script name.
  465.  
  466.    After locating your script, *perl* compiles it to an internal form.
  467. If the script is syntactically correct, it is executed.
  468.  
  469. * Menu:
  470.  
  471. * Options::             Command line options.
  472.  
  473. 
  474. File: perl.info,  Node: Options,  Up: Perl Startup
  475.  
  476. Options
  477. =======
  478.  
  479.    Note: on first reading this section may not make much sense to you.
  480. It's here at the front for easy reference.
  481.  
  482.    A single-character option may be combined with the following option,
  483. if any.  This is particularly useful when invoking a script using the
  484. `#!' construct which only allows one argument.  Example:
  485.  
  486.      #!/usr/bin/perl -spi.bak        # same as -s -p -i.bak
  487.      ...
  488.  
  489. Options include:
  490.  
  491. `-0 digits'
  492.      specifies the record separator ($/) as an octal number.  If there
  493.      are no digits, the null character is the separator.  Other
  494.      switches may precede or follow the digits.  For example, if you
  495.      have a version of `find' which can print filenames terminated by
  496.      the null character, you can say this:
  497.  
  498.           find . -name '*.bak' -print0 | perl -n0e unlink
  499.  
  500.      The special value `00' will cause Perl to slurp files in paragraph
  501.      mode.  The value `0777' will cause Perl to slurp files whole since
  502.      there is no legal character with that value.
  503.  
  504. `-a'
  505.      turns on autosplit mode when used with a `-n' or `-p'.  An
  506.      implicit split command to the `@F' array is done as the first thing
  507.      inside the implicit while loop produced by the `-n' or `-p'.
  508.  
  509.           perl -ane 'print pop(@F), "\n";'
  510.  
  511.      is equivalent to
  512.  
  513.           while (<>) {
  514.                   @F = split(' ');
  515.                   print pop(@F), "\n";
  516.           }
  517.  
  518. `-c'
  519.      causes *perl* to check the syntax of the script and then exit
  520.      without executing it.
  521.  
  522. `-d'
  523.      runs the script under the perl debugger.  *Note Debugging::, for
  524.      more info.
  525.  
  526. `-D number'
  527.      sets debugging flags.  To watch how it executes your script, use
  528.      `-D14'.  (This only works if debugging is compiled into your
  529.      *perl*.)  Another nice value is `-D1024', which lists your
  530.      compiled syntax tree.  And `-D512' displays compiled regular
  531.      expressions.
  532.  
  533. `-e commandline'
  534.      may be used to enter one line of script.  Multiple `-e' commands
  535.      may be given to build up a multi-line script.  If `-e' is given,
  536.      *perl* will not look for a script filename in the argument list.
  537.  
  538. `-i extension'
  539.      specifies that files processed by the `<>' construct are to be
  540.      edited in-place.  It does this by renaming the input file, opening
  541.      the output file by the same name, and selecting that output file
  542.      as the default for print statements.  The extension, if supplied,
  543.      is added to the name of the old file to make a backup copy.  If no
  544.      extension is supplied, no backup is made.  Saying
  545.  
  546.           perl -p -i.bak -e "s/foo/bar/;" ...
  547.  
  548.      is the same as using the script:
  549.  
  550.           #!/usr/bin/perl -pi.bak
  551.           s/foo/bar/;
  552.  
  553.      which is equivalent to
  554.  
  555.           #!/usr/bin/perl
  556.           while (<>) {
  557.                   if ($ARGV ne $oldargv) {
  558.                           rename($ARGV, $ARGV . '.bak');
  559.                           open(ARGVOUT, ">$ARGV");
  560.                           select(ARGVOUT);
  561.                           $oldargv = $ARGV;
  562.                   }
  563.                   s/foo/bar/;
  564.           }
  565.           continue {
  566.               print;      # this prints to original filename
  567.           }
  568.           select(STDOUT);
  569.  
  570.      except that the `-i' form doesn't need to compare `$ARGV' to
  571.      `$oldargv' to know when the filename has changed.  It does,
  572.      however, use `ARGVOUT' for the selected filehandle.  Note that
  573.      `STDOUT' is restored as the default output filehandle after the
  574.      loop.
  575.  
  576.      You can use `eof' to locate the end of each input file, in case you
  577.      want to append to each file, or reset line numbering (*note
  578.      Input/Output::., for an example).
  579.  
  580. `-I directory'
  581.      may be used in conjunction with `-P' to tell the C preprocessor
  582.      where to look for include files.  By default `/usr/include' and
  583.      `/usr/lib/perl' are searched.
  584.  
  585. `-l octnum'
  586.      enables automatic line-ending processing.  It has two effects:
  587.      first, it automatically chops the line terminator when used with
  588.      `-n' or `-p', and second, it assigns `$\' to have the value of
  589.      OCTNUM so that any print statements will have that line terminator
  590.      added back on.  If OCTNUM is omitted, sets `$\' to the current
  591.      value of `$/'.  For instance, to trim lines to 80 columns:
  592.  
  593.           perl -lpe 'substr($_, 80) = ""'
  594.  
  595.      Note that the assignment `$\ = $/' is done when the switch is
  596.      processed, so the input record separator can be different than the
  597.      output record separator if the `-l' switch is followed by a `-0'
  598.      switch:
  599.  
  600.           gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
  601.  
  602.      This sets `$\' to newline and then sets `$/' to the null character.
  603.  
  604. `-n'
  605.      causes *perl* to assume the following loop around your script,
  606.      which makes it iterate over filename arguments somewhat like `sed
  607.      -n' or `awk':
  608.  
  609.           while (<>) {
  610.                   ...         # your script goes here
  611.           }
  612.  
  613.      Note that the lines are *not* printed by default.  See `-p' option
  614.      to have lines printed.  Here is an efficient way to delete all
  615.      files older than a week:
  616.  
  617.      [ before version 4.003 ]
  618.           find . -mtime +7 -print | perl -ne 'chop;unlink;'
  619.  
  620.      [ version 4.003 and beyond ]
  621.           find . -mtime +7 -print | perl -nle 'unlink;'
  622.  
  623.      This is faster than using the `-exec' switch of find because you
  624.      don't have to start a process on every filename found.
  625.  
  626. `-p'
  627.      causes *perl* to assume the following loop around your script,
  628.      which makes it iterate over filename arguments somewhat like `sed':
  629.  
  630.           while (<>) {
  631.                   ...         # your script goes here
  632.           } continue {
  633.                   print;
  634.           }
  635.  
  636.      Note that the lines are printed automatically.  To suppress
  637.      printing use the `-n' switch.  A `-p' overrides a `-n' switch.
  638.  
  639. `-P'
  640.      causes your script to be run through the C preprocessor before
  641.      compilation by *perl*.  (Since both comments and cpp directives
  642.      begin with the `#' character, you should avoid starting comments
  643.      with any words recognized by the C preprocessor such as `if',
  644.      `else' or `define'.)
  645.  
  646. `-s'
  647.      enables some rudimentary switch parsing for switches on the
  648.      command line after the script name but before any filename
  649.      arguments (or before a `--').  Any switch found there is removed
  650.      from `@ARGV' and sets the corresponding variable in the *perl*
  651.      script.  The following script prints `true' if and only if the
  652.      script is invoked with a `-xyz' switch.
  653.  
  654.           #!/usr/bin/perl -s
  655.           if ($xyz) { print "true\n"; }
  656.  
  657. `-S'
  658.      makes *perl* use the `PATH' environment variable to search for the
  659.      script (unless the name of the script starts with a slash).
  660.      Typically this is used to emulate `#!' startup on machines that
  661.      don't support `#!', in the following manner:
  662.  
  663.           #!/usr/bin/perl
  664.           eval "exec /usr/bin/perl -S $0 $*"
  665.                   if $running_under_some_shell;
  666.  
  667.      The system ignores the first line and feeds the script to
  668.      `/bin/sh', which proceeds to try to execute the *perl* script as a
  669.      shell script.  The shell executes the second line as a normal shell
  670.      command, and thus starts up the *perl* interpreter.  On some
  671.      systems `$0' doesn't always contain the full pathname, so the `-S'
  672.      tells *perl* to search for the script if necessary.  After *perl*
  673.      locates the script, it parses the lines and ignores them because
  674.      the variable `$running_under_some_shell' is never true.  A better
  675.      construct than `$*' would be `${1+"$@"}', which handles embedded
  676.      spaces and such in the filenames, but doesn't work if the script
  677.      is being interpreted by `csh'.  In order to start up `sh' rather
  678.      than `csh', some systems may have to replace the `#!' line with a
  679.      line containing just a colon, which will be politely ignored by
  680.      *perl*.  Other systems can't control that, and need a totally
  681.      devious construct that will work under any of `csh', `sh' or
  682.      `perl', such as the following:
  683.  
  684.           eval '(exit $?0)' && eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
  685.           & eval 'exec /usr/bin/perl -S $0 $argv:q'
  686.                   if 0;
  687.  
  688. `-u'
  689.      causes *perl* to dump core after compiling your script.  You can
  690.      then take this core dump and turn it into an executable file by
  691.      using the `undump' program (not supplied).  This speeds startup at
  692.      the expense of some disk space (which you can minimize by
  693.      stripping the executable).  (Still, a "hello world" executable
  694.      comes out to about 200K on my machine.)  If you are going to run
  695.      your executable as a set-id program then you should probably
  696.      compile it using taintperl rather than normal perl.  If you want
  697.      to execute a portion of your script before dumping, use the `dump'
  698.      operator instead.  Note: availability of `undump' is platform
  699.      specific and may not be available for a specific port of *perl*.
  700.  
  701. `-U'
  702.      allows *perl* to do unsafe operations.  Currently the only
  703.      `unsafe' operations are the unlinking of directories while running
  704.      as superuser, and running setuid programs with fatal taint checks
  705.      turned into warnings.
  706.  
  707. `-v'
  708.      prints the version and patchlevel of your *perl* executable.
  709.  
  710. `-w'
  711.      prints warnings about identifiers that are mentioned only once, and
  712.      scalar variables that are used before being set.  Also warns about
  713.      redefined subroutines, and references to undefined filehandles or
  714.      filehandles opened readonly that you are attempting to write on.
  715.      Also warns you if you use `==' on values that don't look like
  716.      numbers, and if your subroutines recurse more than 100 deep.
  717.  
  718. `-x directory'
  719.      tells *perl* that the script is embedded in a message.  Leading
  720.      garbage will be discarded until the first line that starts with
  721.      `#!' and contains the string "perl".  Any meaningful switches on
  722.      that line will be applied (but only one group of switches, as with
  723.      normal `#!' processing).  If a directory name is specified, *perl*
  724.      will switch to that directory before running the script.  The `-x'
  725.      switch only controls the the disposal of leading garbage.  The
  726.      script must be terminated with `__END__' if there is trailing
  727.      garbage to be ignored (the script can process any or all of the
  728.      trailing garbage via the `DATA' filehandle if desired).
  729.  
  730.