home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / perlref-4.036.1 / refbase.tex < prev    next >
Encoding:
Text File  |  1993-05-17  |  47.4 KB  |  1,668 lines

  1. \def\revision{1}
  2. \documentstyle{refbase}
  3.  
  4. \begin{document}
  5.  
  6.  
  7. \begin{titlepage}
  8.  
  9. \hbox{ }
  10. \end{titlepage}
  11.  
  12. \begin{titlepage}
  13. \addtolength{\evensidemargin}{2cm}
  14. \addtolength{\textwidth}{-2.1cm}
  15. \vspace*{2.5cm}
  16.  
  17. \unnumbered{Perl Reference Guide}
  18. {\bf for Perl version \perlrev}
  19.  
  20. \vskip1cm
  21. Perl program designed and created by \\
  22. Larry Wall \<lwall@netlabs.com\>
  23.  
  24. \vskip1cm
  25. Reference guide designed and created by \\
  26. Johan Vromans \<jv@mh.nl\>
  27.  
  28. \vskip1.3cm
  29. \unnumbered{Contents}
  30.  
  31. \newcounter{xx}
  32. \begin{list}{\thexx.}
  33. {\setlength{\topsep}{0pt plus 1pt}
  34.  \setlength{\itemsep}{0pt plus 1pt}
  35.  \setlength{\parsep}{0pt plus 1pt}
  36.  \usecounter{xx}}
  37. \item Command line options
  38. \item Literals
  39. \item Variables
  40. \item Statements
  41. \item Flow control
  42. \item Operators
  43. \item File test operators
  44. \item Arithmetic functions
  45. \item Conversion functions
  46. \item Structure conversion
  47. \item String functions
  48. \item Array and list functions
  49. \item File operations
  50. \item Directory reading routines
  51. \item Input / Output
  52. \item Search and replace functions
  53. \item System interaction
  54. \item Networking
  55. \item SystemV IPC
  56. \item Miscellaneous
  57. \item Formats
  58. \item Info from system files
  59. \item Regular expressions
  60. \item Special variables
  61. \item Special arrays
  62. \item The perl debugger
  63. \item Environment variables
  64. \end{list}
  65. \vskip1cm
  66. {\catcode`\%=\other \small {Rev. \refrev}}
  67. \end{titlepage}
  68.  
  69. \unnumbered{Conventions}
  70.  
  71. \begin{enum}{2cm}
  72. \Xi{|fixed|} denotes literal text.
  73.  
  74. \Xi{<this>} means variable text, i.e. things you must fill in.
  75.  
  76. \Xi{<this>\dag} means that <this> will default to |$_| if omitted.
  77.  
  78. \Xi{\kwd{word}} is a keyword, i.e. a word with a special meaning.
  79.  
  80. \Xi{\fbox{<ret>}} denotes pressing a keyboard key.
  81.  
  82. \Xi{[\ldots]} denotes an optional part.
  83.  
  84. \Xi{(\ldots)*} means that the parentheses may be omitted.
  85.  
  86. \end{enum}
  87.  
  88.  
  89. \section{Command line options} 
  90.  
  91. \begin{enum}{1cm}
  92.  
  93. \Xi{|-a|} turns on autosplit mode when used with |-n| or
  94. |-p|. Splits to |@F|.
  95.  
  96. \Xi{|-c|} checks syntax but does not execute.
  97.  
  98. \Xi{|-d|} runs the script under the debugger. Use |-de 0| to
  99. start the debugger without a script.
  100.  
  101. \Xi{|-D| <number>} sets debugging flags. 
  102.  
  103. \Xi{|-e| <commandline>} may be used to enter one line of
  104. script. Multiple |-e| commands may be given to build up a
  105. multi-line script.
  106.  
  107. \Xi{|-i| <ext>} files processed by the |<>| construct are
  108. to be edited in-place.
  109.  
  110. \Xi{|-I| <dir>} with |-P|: tells the C preprocessor where
  111. to look for include files. The directory is prepended to |@INC|.
  112.  
  113. \Xi{|-l| [ <octnum> ] } enables automatic line ending processing, e.g. |-l013|.
  114.  
  115. \Xi{|-n|} assumes an input loop around your script. Lines are not
  116. printed.
  117.  
  118. \Xi{|-p|} assumes an input loop around your script. Lines are
  119. printed.
  120.  
  121. \Xi{|-P|} runs the C preprocessor on the script before
  122. compilation by perl.
  123.  
  124. \Xi{|-s|} interprets ``|-xxx|'' on the command line as
  125. switches and sets the corresponding variables \$|xxx| in the script.
  126.  
  127. \Xi{|-S|} uses the |PATH| environment variable to search for
  128. the script.
  129.  
  130. \Xi{|-u|} dumps core after compiling the script. To be used with
  131. the {\it undump\/} program (where available).
  132.  
  133. \Xi{|-U|} allows perl to do unsafe operations.
  134.  
  135. \Xi{|-v|} prints the version and patchlevel of your perl
  136. executable.
  137.  
  138. \Xi{|-w|} prints warnings about possible spelling errors and
  139. other error-prone constructs in the script.
  140.  
  141. \Xi{|-x|} extracts perl program from input stream.
  142.  
  143. \Xi{|-0| <val>} (that's the number zero) designates an
  144. initial value for the record terminator \$|/|.
  145. See also |-l|.
  146.  
  147. \end{enum}
  148.  
  149. \makeuppage
  150.  
  151. \section{Literals} 
  152.  
  153. Numeric: |123  1_234  123.4  5E-10  0xff| (hex)|  0377| (octal).
  154.  
  155. \hangindent=2cm\hangafter=1
  156. String: |'abc'| literal string, no variable interpolation nor
  157. escape characters, except |\'| and |\\|. Also: |q/abc/|.
  158. \newline (Almost any pair of delimiters can be used instead of |/.../|.)
  159.  
  160. \hangindent=2cm\hangafter=1
  161. \makebox[1cm]{}|"abc"|
  162. Variables are interpolated and escape sequences are processed. 
  163. \newline Also: |qq/abc/|.
  164. \newline Escape sequences: |\t| (Tab), |\n| (Newline), |\r| (Return),
  165. |\f| (Formfeed), |\b| (Backspace), |\a| (Alarm), |\e|
  166. (Escape), |\033|(octal), |\x1b|(hex), |\c[| (control).
  167. \newline |\l| and |\u| lowcase/upcase the following character; 
  168. \newline |\L| and |\U| lowcase/upcase until a |\E| is encountered.
  169.  
  170.  
  171. \hangindent=2cm\hangafter=1
  172. \makebox[1cm]{}|`|<command>|`|
  173. evaluates to the output of the <command>. 
  174. \newline Also: |qx/|<command>|/|.
  175.  
  176. \hangindent=1cm\hangafter=1
  177. Array: |(1,2,3)|. |()| is an empty array.  
  178. \newline Also: |($a,$b,@rest) = (1,2,...);|
  179. \newline |(1..4)| is the same as |(1,2,3,4)|. Likewise |('abc'..'ade')|
  180.  
  181. \hangindent=1cm\hangafter=1
  182. Associative array:
  183. |(|<key1>|,|<val1>|,|<key2>|,|<val2>|,...)|
  184.  
  185. \hangindent=1cm\hangafter=1
  186. Filehandles: 
  187. \newline Pre-defined: |<STDIN>|, |<STDOUT>|, |<STDERR>|, |<ARGV>|,
  188. |<DATA>|;
  189. \newline User-specified: |<|<handle>|>|, |<$|<var>|>|.
  190. \newline |<>| is the input stream formed by the files specified in
  191. |@ARGV|, or standard input if no arguments are supplied.
  192.  
  193. \hangindent=1cm\hangafter=1
  194. Globs: |<|<pattern>|>| evaluates to all filenames according
  195. to the pattern.
  196. \newline Use |<${|<var>|}>| to glob from a variable.
  197.  
  198. \hangindent=1cm\hangafter=1
  199. Here-Is: |<<|<identifier>
  200. \newline {\it See the manual for details.}
  201.  
  202. \hangindent=1cm\hangafter=1
  203. Special tokens:
  204. \newline \_\,\_|FILE|\_\,\_: filename; \_\,\_|LINE|\_\,\_: line number.
  205. \newline \_\,\_|END|\_\,\_: end of program; remaining lines can be read using
  206. \<<data>\>.
  207.  
  208.  
  209. \section{Variables} 
  210.  
  211. \begin{enum}{3.2cm}
  212.  
  213. \Xi{|\$var|} a simple scalar variable
  214.  
  215. \Xi{|\$var[28]|} 29th element of array |@var| (the |[]| are
  216. part of it)
  217.  
  218. \Xi{|\$var\{'Feb'\}|} one value from associative array |%var|
  219.  
  220. \Xi{|\$\#var|} last index of array |@var|
  221.  
  222. \Xi{|@var|} the entire array;
  223. \\
  224. in scalar context: the number of elements in the array
  225.  
  226. \Xi{|@var[3,4,5]|} a slice of the array |@var|
  227.  
  228. \Xi{|@var\{'a','b'\}|} a slice of |%var|; same as
  229. |($var{'a'},$var{'b'})|
  230.  
  231. \Xi{|\%var|} the entire associative array;
  232. \\
  233. in scalar context: TRUE if the array has elements
  234.  
  235. \Xj{|\$var\{'a',1,...\}|} emulates a multi-dimensional array
  236.  
  237. \Xi{|('a'..'z')[4,7,9]|} a slice of an array literal
  238.  
  239. \Xi{|*|<name>} refers to all objects represented by <name>.
  240. ``|*name1 = *name2|'' makes |name1| a reference to |name2|.
  241.  
  242. \end{enum}
  243.  
  244.  
  245. \section{Statements} 
  246.  
  247. Every statement is an expression, optionally followed by a modifier,
  248. and terminated by a semicolon.  The semicolon may be omitted if the
  249. statement is the final one in a BLOCK.
  250.  
  251. Execution of expressions can depend on other expressions using one of
  252. the modifiers \kwd{if}, \kwd{unless}, \kwd{while} or \kwd{until},
  253. e.g.:
  254.  
  255. \quad    <expr1> \kwd{if} <expr2> |;| \\
  256. \quad    <expr1> \kwd{until} <expr2> |;|
  257.  
  258. Also, by using one of the logical operators \|\|, |&&| or |? :|, e.g.:
  259.  
  260. \quad    <expr1> \|\| <expr2> |;| \\
  261. \quad    <expr1> |?| <expr2> |:| <expr3> |;| 
  262.  
  263. Statements can be combined to form a <block> when enclosed in |{}|.
  264.  
  265. Compound statements may be used to control flow:
  266.  
  267. \quad    \kwd{if} |(|<expr>|)| <block> [ [ \kwd{elsif}
  268.     |(|<expr>|)| <BLOCK ...> ] \kwd{else}
  269.     <block> ]
  270. \\
  271. \quad    \kwd{unless} |(|<expr>|)| <block> [ \kwd{else}
  272.     <block> ]
  273. \\
  274. \quad    [ <label>\kwd{:} ] \kwd{while} |(|<expr>|)|
  275.     <block> [ \kwd{continue} <block> ]
  276. \\
  277. \quad    [ <label>\kwd{:} ] \kwd{until} |(|<expr>|)|
  278.     <block> [ \kwd{continue} <block> ]
  279. \\
  280. \quad    [ <label>\kwd{:} ] \kwd{for} |(|<expr>|;|
  281.     <expr>|;| <expr>|)| <block>
  282. \\
  283. \quad    [ <label>\kwd{:} ] \kwd{foreach} <var>\dag
  284.     |(|<array>|)| <block>
  285. \\
  286. \quad    [ <label>\kwd{:} ] <block> [ \kwd{continue} < block> ]
  287.  
  288. Special forms are:
  289.  
  290. \quad    \kwd{do} <block> \kwd{while} <expr> |;| \\
  291. \quad    \kwd{do} <block> \kwd{until} <expr> |;| \\
  292.  
  293. which are guaranteed to perform <block> once before testing <expr>.
  294.  
  295.  
  296.  
  297. \section{Flow control} 
  298.  
  299. \begin{enum}{1cm}
  300.  
  301. \Xi{\kwd{do} <block>}
  302. Returns the value of the last command in the sequence of commands indicated by <block>. \kwd{next}, \kwd{last} and \kwd{redo}
  303.  cannot be used here.
  304.  
  305. \Xi{\kwd{do} <subroutine>\kwd{(LIST)}} 
  306. Executes a <subroutine> declared by a \kwd{sub} declaration, and
  307. returns the value of the last expression evaluated in <subroutine> .
  308. \newline Preferred form is: |&|<subroutine> .
  309.  
  310. \Xi{\kwd{do} <FILENAME>}
  311. Executes the contents of <filename> as a perl script. Errors are
  312. returned in |$@|.
  313. \newline Preferred form is: \kwd{require} <filename> .
  314.  
  315. \Xi{\kwd{goto} <label>}
  316. Continue execution at the specified label.
  317.  
  318. \Xi{\kwd{last} [<label>]}
  319. Immediately exits the loop in question. Skips continue block.
  320.  
  321. \Xi{\kwd{next} [<label>]}
  322. Starts the next iteration of the loop.
  323.  
  324. \Xi{\kwd{redo} [<label>]}
  325. Restarts the loop block without evaluating the conditional again.
  326.  
  327. \Xi{\kwd{return} <expr>}
  328. Returns from a subroutine with the value specified.
  329.  
  330. \end{enum}
  331.  
  332.  
  333. \section{Operators} 
  334.  
  335. \begin{tabbing}
  336. |    |\=|    |\= \kill
  337. |+ -| \> |* /| \> Addition, subtraction, multiplication, division. \\
  338. |%| \> \> Modulo division. \\
  339. \| \& \> \^ \> Bitwise or, bitwise and, bitwise exclusive or. \\
  340. |>>| \> |<<| \> Bitwise shift right, bitwise shift left. \\
  341. |**| \> \> Exponentiation. \\
  342. |!| \> \> Negation (unary). \\
  343. |~| \> \> Bitwise complement (unary). \\
  344. |.| \> \> Concatenation of two strings. \\
  345. \kwd{x} \> \> Returns a string or array consisting of the left operand
  346. (an array or \\
  347. \> \> a string) repeated the number of times specified by the right operand.
  348. \end{tabbing}
  349.  
  350. All of the above operators also have an assignment operator, e.g. ``|.=|''.
  351.  
  352. \begin{tabbing}
  353. |    |\=|    |\= \kill
  354. |++| \> |--| \> Auto-increment (magical on strings), auto-decrement. \\
  355. |? :|\>      \> Alternation (if-then-else) operator. \\
  356. \|\| \> \&\&   \> Logical or, logical and. \\
  357. |=|\,|=| \> |!=| \> Numeric equality, inequality. \\
  358. \kwd{eq} \> \kwd{ne} \> String equality, inequality. \\
  359. |<|  \>  |>|  \> Numeric less than, greater than. \\
  360. \kwd{lt} \> \kwd{gt} \> String less than, greater than. \\
  361. |<=| \> |>=| \> Numeric less (greater) than or equal to. \\
  362. \kwd{le} \> \kwd{ge} \> String less (greater) than or equal. \\
  363. |<=>| \> \> Numeric compare. Returns -1, 0 or 1. \\
  364. \kwd{cmp} \> \> String compare. Returns -1, 0 or 1. \\
  365. |=~| \> |!~| \> Search pattern, substitution, or translation (negated). \\
  366. |..| \> \> Enumeration, also input line range operator. \\
  367. |,| \> \> Comma operator.
  368. \end{tabbing}
  369.  
  370.  
  371. \section{File test operators} 
  372.  
  373. These unary operators takes one argument, either a filename or a
  374. filehandle, and tests the associated file to see if something is true
  375. about it. If the argument is omitted, tests |$_| (except for |-t,|
  376. which tests |STDIN|). If the special argument |_| (underscore) is
  377. passed, uses the info of the preceding test. 
  378.  
  379. \begin{enum}{2.5cm}
  380.  
  381. \Xi{|-r -w -x|}  File is readable/writable/executable by effective uid/gid.
  382.  
  383. \Xi{|-R -W -X|}  File is readable/writable/executable by real uid/gid.
  384.  
  385. \Xi{|-o  -O|}  File is owned by effective/real uid. 
  386.  
  387. \Xi{|-e  -z|}  File exists / has zero size. 
  388.  
  389. \Xi{|-s|}  File exists and has non-zero size. Returns the size.
  390.  
  391. \Xi{|-f  -d|}  File is a plain file, a directory.
  392.  
  393. \Xi{|-l  -S  -p|}  File is a symbolic link, a socket, a named pipe (FIFO). 
  394.  
  395. \Xi{|-b  -c|}  File is a block/character special file. 
  396.  
  397. \Xi{|-u  -g  -k|}  File has setuid/setgid/sticky bit set. 
  398.  
  399. \Xi{|-t|}  Tests if filehandle (|STDIN| by default) is opened to a tty.
  400.  
  401. \Xi{|-T  -B|}  File is a text/non-text (binary) file.  |-T| and |-B|
  402. return TRUE on a null file, or a file at EOF when testing a filehandle. 
  403.  
  404. \Xi{|-M  -A  -C|}  File modification / access / inode change time. Measured
  405. in days since this program started. See also |$^T| in section
  406. ``Special~Variables''.
  407.  
  408. \end{enum}
  409.  
  410. \makeuppage
  411.  
  412. A <list> is a (possibly parenthesised) list of expressions, variables
  413. or <list>s. An array variable or an array slice may always be used
  414. instead of a <list>.  
  415.  
  416. \section{Arithmetic functions} 
  417.  
  418. \begin{enum}{1cm}
  419.  
  420. \Xi{\kwd{atan2(}<y>\kwd{,}<x>\kwd{)}}
  421. Returns the arctangent of <Y>/<X> in the range -$\pi$ to $\pi$.
  422.  
  423. \Xi{\kwd{cos(}\oEXPR \kwd{)}*}
  424. Returns the cosine of <expr> (expressed in radians).
  425.  
  426. \Xi{\kwd{exp(}\oEXPR \kwd{)}*}
  427. Returns |e| to the power of <expr>.
  428.  
  429. \Xi{\kwd{int(}\oEXPR \kwd{)}*}
  430. Returns the integer portion of <expr>.
  431.  
  432. \Xi{\kwd{log(}\oEXPR \kwd{)}*}
  433. Returns natural logarithm (base |e|) of <expr>.
  434.  
  435. \Xi{\kwd{rand}[\kwd{(}<expr>\kwd{)}*]}
  436. Returns a random fractional number between 0 and the value of <expr>.
  437. If <expr> is omitted, returns a value between 0 and 1. 
  438.  
  439. \Xi{\kwd{sin(}\oEXPR \kwd{)}*}
  440. Returns the sine of <expr> (expressed in radians).
  441.  
  442. \Xi{\kwd{sqrt(}\oEXPR \kwd{)}*}
  443. Return the square root of <expr>.
  444.  
  445. \Xi{\kwd{srand}[\kwd{(}<expr>\kwd{)}*]}
  446. Sets the random number seed for the rand operator.
  447.  
  448. \Xi{\kwd{time}}
  449. Returns the number of seconds since January 1, 1970. Suitable for
  450. feeding to \kwd{gmtime} and \kwd{localtime}. 
  451.  
  452. \end{enum}
  453.  
  454.  
  455. \section{Conversion functions} 
  456.  
  457. \begin{enum}{1cm}
  458.  
  459. \Xi{\kwd{gmtime(}<expr>\kwd{)}*}
  460. Converts a time as returned by the \kwd{time} function to a 9-element
  461. array (\$sec, \$min, \$hour, \$mday, \$mon, \$year, \$wday,
  462. \$yday, \$isdst) with the time analyzed for the Greenwich timezone.
  463. \$mon has the range 0..11 and \$wday has the range 0..6.
  464.  
  465. \Xi{\kwd{hex(}\oEXPR\kwd{)}*}
  466. Returns the decimal value of <expr> interpreted as an hex string.
  467.  
  468. \Xi{\kwd{localtime(}<expr>\kwd{)}*}
  469. Converts a time as returned by the \kwd{time} function to a 9-element
  470. array with the time analyzed for the local timezone. 
  471.  
  472. \Xi{\kwd{oct(}\oEXPR\kwd{)}*}
  473. Returns the decimal value of <expr> interpreted as an octal string. If
  474. <expr> starts off with |0x|, interprets it as a hex string instead.
  475.  
  476. \Xi{\kwd{ord(}\oEXPR\kwd{)}*}
  477. Returns the ascii value of the first character of <expr>.
  478.  
  479. \Xi{\kwd{vec(}<expr>\kwd{,}<offset>\kwd{,}<bits>\kwd{)}}
  480. Treats <expr> as a string of unsigned ints, and yields the bit at
  481. <offset>. <bits> must be between 1 and 32. May be used as an lvalue.
  482.  
  483. \end{enum}
  484.  
  485.  
  486. \section{Structure conversion} 
  487.  
  488. \begin{enum}{1cm}
  489.  
  490. \Xi{\kwd{pack(}<template>\kwd{,}<list>\kwd{)}}
  491. Packs the values into a binary structure using <template>.
  492.  
  493. \Xi{\kwd{unpack(}<template>\kwd{,}<expr>\kwd{)}}
  494. Unpacks the structure <expr> into an array, using <template>.
  495.  
  496. <template> is a sequence of characters as follows:
  497.  
  498. \begin{tabbing}
  499. |  |\=|a |\=|/ |\=|A  |\= \kill
  500.   \> |a| \> / \> |A| \> Ascii string, null / space padded \\
  501.   \> |b| \> / \> |B| \> Bit string in ascending / descending order \\
  502.   \> |c| \> / \> |C| \> Native / unsigned char value \\
  503.   \> |f| \> / \> |d| \> Single / double float in native format \\
  504.   \> |h| \> / \> |H| \> Hex string, low / high nybble first. \\
  505.   \> |i| \> / \> |I| \> Signed / unsigned integer value \\
  506.   \> |l| \> / \> |L| \> Signed / unsigned long value \\
  507.   \> |n| \> / \> |N| \> Short / long in network (big endian) byte order \\
  508.   \> |s| \> / \> |S| \> Signed / unsigned short value \\
  509.   \> |u| \> / \> |p| \> Uuencoded string / Pointer to a string \\
  510.   \> |v| \> / \> |V| \> Short / long in VAX (little endian) byte order \\
  511.   \> |x| \> / \> |@| \> Null byte / null fill until position \\
  512.   \> |X| \>   \>     \> Backup a byte
  513. \end{tabbing}
  514.  
  515. Each character may be followed by a decimal number which will be used
  516. as a repeat count, an |*| specifies all remaining arguments. \\
  517. If the format is preceded with |%|<n>, \kwd{unpack} returns an
  518. <n>-bit checksum instead. \\
  519. Spaces may be included in the template for readability purposes.
  520.  
  521. \end{enum}
  522.  
  523.  
  524. \section{String functions} 
  525.  
  526. \begin{enum}{1cm}
  527.  
  528. \Xi{\kwd{chop(}<list>\dag\kwd{)}}
  529. Chops off the last character on all elements of the list; returns the
  530. last chopped character. The parentheses may be omitted if <list> is a
  531. single variable.
  532.  
  533. \Xi{\kwd{crypt(}<plaintext>\kwd{,}<salt>\kwd{)}}
  534. Encrypts a string.
  535.  
  536. \Xi{\kwd{eval(}\oEXPR \kwd{)}*}
  537. <expr> is parsed and executed as if it were a perl program. The value
  538. returned is the value of the last expression evaluated. If there is a
  539. syntax error or runtime error, an undefined string is returned by
  540. \kwd{eval}, and |$@| is set to the error message.
  541.  
  542. \Xi{\kwd{eval\{}<expr>\kwd{;...\}}}
  543. Executes the code between \{ and \}. Traps runtime errors as described
  544. above.
  545.  
  546. \Xi{\kwd{index(}<str>\kwd{,}<substr>[\kwd{,}<offset>]\kwd{)}}
  547. Returns the position of <substr> in <str> at or after <offset>. If the
  548. substring is not found, returns |$[-1|.
  549.  
  550. \Xi{\kwd{length(}\oEXPR\kwd{)}*}
  551. Returns the length in characters of the value of <expr>.
  552.  
  553. \Xi{\kwd{rindex(}<str>\kwd{,}<substr>[\kwd{,}<offset>]\kwd{)}}
  554. Returns the position of the last <substr> in <str> at or
  555. before <offset>.
  556.  
  557. \Xi{\kwd{substr(}<expr>\kwd{,}<offset>[\kwd{,}<len>]\kwd{)}}
  558. Extracts a substring out of <expr> and returns it. If <offset>
  559. is negative, counts from the end of the string. May be used as an lvalue.
  560.  
  561. \end{enum}
  562.  
  563. \makeuppage
  564.  
  565. \section{Array and list functions} 
  566.  
  567. \begin{enum}{1cm}
  568.  
  569. \Xi{\kwd{delete} \$<array>\{<key>\}}
  570. Deletes the specified value from the specified associative array.
  571. Returns the deleted value. 
  572.  
  573. \Xi{\kwd{each(}|\%|<array>\kwd{)}*}
  574. Returns a 2-element array consisting of the key and value for the next
  575. value of an associative array. Entries are returned in an apparently
  576. random order. When the array is entirely read, a null array is
  577. returned. The next call to \kwd{each} after that will start iterating again.
  578.  
  579. \Xi{\kwd{grep(}<expr>\kwd{,}<list>\kwd{)}}
  580. Evaluates <expr> for each element of the <list>, locally setting |$_|
  581. to refer to the element. Modifying |$_| will modify the corresponding
  582. element from <list>. Returns array of elements from <list> for which
  583. <expr> returned true. 
  584.  
  585. \Xi{\kwd{join(}<expr>\kwd{,}<list>\kwd{)}}
  586. Joins the separate strings of <list> into a single string with fields
  587. separated by the value of <expr>, and returns the string.
  588.  
  589. \Xi{\kwd{keys(}|\%|<array>\kwd{)}*}
  590. Returns an array with of all the keys of the named
  591. associative array.
  592.  
  593. \Xi{\kwd{pop(}|@|<array>\kwd{)}*}
  594. Pops and returns the last value of the array, shortens the array by 1. 
  595.  
  596. \Xi{\kwd{push(}|@|<array>\kwd{,}<list>\kwd{)}}
  597. Pushes the values of <list> onto the end of <array>. The length of the
  598. array increases by the length of <list>.
  599.  
  600. \Xi{\kwd{reverse(}<list>\kwd{)}*}
  601. In array context: returns the <list> in reverse order. \\
  602. In scalar
  603. context: returns the first element of <list> with bytes reversed. 
  604.  
  605. \Xi{\kwd{scalar(}|@|<array>\kwd{)}}
  606. Returns the number of elements in the array.
  607.  
  608. \Xi{\kwd{scalar(}|\%|<array>\kwd{)}}
  609. Returns TRUE if the associative array has elements defined.
  610.  
  611. \Xi{\kwd{shift}[\kwd{(}|@|<array>\kwd{)}*]}
  612. Shifts the first value of the array off and returns it, shortening the
  613. array by 1 and moving everything down. If |@|<array> is omitted, shifts
  614. |@ARGV| in main and |@_| in subroutines.  
  615.  
  616. \Xi{\kwd{sort(} [<subroutine> ] <list>\kwd{)}*}
  617. Sorts the <list> and returns the sorted array value. If <subroutine>
  618. is specified, gives the name of a subroutine that returns less than
  619. zero, zero, or greater than zero, depending on how the elements of the
  620. array, available to the routine as |$a| and |$b|, are to be ordered.
  621. \\
  622. <SUBROUTINE> may be the name of a user-defined routine, or a <block>
  623. (see ``Statements'' and ``Miscellaneous'').
  624.  
  625. \Xi{\kwd{splice(}|@|<array>\kwd{,}<offset>[\kwd{,}<length>[\kwd{,}<list>]]\kwd{)}}
  626. Removes the elements of |@|<array> designated by <offset> and
  627. <length>, and replaces them with <list> (if specified). \\
  628. Returns the elements removed.
  629.  
  630. \Xi{\kwd{split}[\kwd{(}<pattern>[\kwd{,}\oEXPR [\kwd{,}<limit>]]\kwd{)}]}
  631. Splits a string into an array of strings, and returns it. If <limit>
  632. is specified, splits in no more than that many fields. If <pattern> is
  633. also omitted, splits on whitespace. If
  634. not in array context: returns number of fields and splits to |@_|.
  635. See also: ``Search and Replace Functions''. 
  636.  
  637. \Xi{\kwd{unshift(}|@|<array>\kwd{,}<list>\kwd{)}}
  638. Prepends list to the front of the array, and returns the number of
  639. elements in the new array.
  640.  
  641. \Xi{\kwd{values(}|\%|<array>\kwd{)}*}
  642. Returns a normal array consisting of all the values of the named
  643. associative array. 
  644.  
  645. \end{enum}
  646.  
  647.  
  648.  
  649. \makeupspace{1cm}
  650.  
  651. \section{File operations} 
  652.  
  653. Functions operating on a list of files return the number of files
  654. successfully operated upon.
  655.  
  656. \begin{enum}{1cm}
  657.  
  658. \Xi{\kwd{chmod(}<list>\kwd{)}*}
  659. Changes the permissions of a list of files. The first element of the
  660. list must be the numerical mode. 
  661.  
  662. \Xi{\kwd{chown(}<list>\kwd{)}*}
  663. Changes the owner and group of a list of files. The first two elements
  664. of the list must be the numerical uid and gid. 
  665.  
  666. \Xi{\kwd{truncate(}<file>\kwd{,}<size>\kwd{)}}
  667. truncates <file> to <size>. <file> may be a filename or a filehandle.
  668.  
  669. \Xi{\kwd{link(}<oldfile>\kwd{,}<newfile>\kwd{)}}
  670. Creates a new filename linked to the old filename.
  671.  
  672. \Xi{\kwd{lstat(}<file>\kwd{)}}
  673. Like stat, but does not traverse a final symbolic link.
  674.  
  675. \Xi{\kwd{mkdir(}<dir>\kwd{,}<mode>\kwd{)}}
  676. Creates a directory with given permissions. Sets |$!| on failure.
  677.  
  678. \Xi{\kwd{readlink(}\oEXPR\kwd{)}*}
  679. Returns the value of a symbolic link.
  680.  
  681. \Xi{\kwd{rename(}<oldname>\kwd{,}<newname>\kwd{)}}
  682. Changes the name of a file.
  683.  
  684. \Xi{\kwd{rmdir(}<filename>\dag\kwd{)}*}
  685. Deletes the directory if it is empty. Sets |$!| on failure.
  686.  
  687. \Xi{\kwd{stat(}<file>\kwd{)}}
  688. Returns a 13-element array (\$dev, \$ino, \$mode, \$nlink, \$uid, \$gid,
  689. \$rdev, \$size, \$atime, \$mtime, \$ctime, \$blksize, \$blocks). <file> can
  690. be a filehandle, an expression evaluating to a filename, or |_| to
  691. refer to the last file test operation. 
  692. \\
  693. Returns a null list if the \kwd{stat} fails.
  694.  
  695. \Xi{\kwd{symlink(}<oldfile>\kwd{,}<newfile>\kwd{)}}
  696. Creates a new filename symbolically linked to the old filename.
  697.  
  698. \Xi{\kwd{unlink(}<list>\kwd{)}*}
  699. Deletes a list of files.
  700.  
  701. \Xi{\kwd{utime(}<list>\kwd{)}*}
  702. Changes the access and modification times. The first two elements of
  703. the list must be the numerical access and modification times.
  704.  
  705. \end{enum}
  706.  
  707.  
  708.  
  709. \makeuppage
  710.  
  711. \section{Directory reading routines} 
  712.  
  713. \begin{enum}{1cm}
  714.  
  715. \Xi{\kwd{closedir(}<dirhandle>\kwd{)}*}
  716. Closes a directory opened by opendir.
  717.  
  718. \Xi{\kwd{opendir(}<dirhandle>\kwd{,}<dirname>\kwd{)}}
  719. Opens a directory on the handle specified.
  720.  
  721. \Xi{\kwd{readdir(}<dirhandle>\kwd{)}*}
  722. Returns the next entry (or an array of entries) in the directory.
  723.  
  724. \Xi{\kwd{rewinddir(}<dirhandle>\kwd{)}*}
  725. Positions the directory to the beginning.
  726.  
  727. \Xi{\kwd{seekdir(}<dirhandle>\kwd{,}<pos>\kwd{)}}
  728. Sets position for readdir on the directory.
  729.  
  730. \Xi{\kwd{telldir(}<dirhandle>\kwd{)}*}
  731. Returns the postion in the directory.
  732.  
  733. \end{enum}
  734.  
  735.  
  736. \section{Input / Output} 
  737.  
  738. In input/output operations, <filehandle> may be a filehandle as opened
  739. by the \kwd{open} operator, or a scalar variable which evaluates to
  740. the name of a filehandle to be used.  
  741.  
  742. \begin{enum}{1cm}
  743.  
  744. \Xi{\kwd{binmode(}<filehandle>\kwd{)}*}
  745. Arranges for the file opened on <filehandle> to be read in ``binary''
  746. mode as opposed to ``text'' mode (MS-DOS only). 
  747.  
  748. \Xi{\kwd{close(}<filehandle>\kwd{)}*}
  749. Closes the file or pipe associated with the file handle.
  750.  
  751. \Xi{\kwd{dbmclose(}|\%|<array>\kwd{)}*}
  752. Breaks the binding between the array and the dbm file.
  753.  
  754. \Xi{\kwd{dbmopen(}|\%|<array>\kwd{,}<dbmname>\kwd{, }<mode>\kwd{)}}
  755. Binds a dbm or ndbm file to the associative array. If the database
  756. does not exist, it is created with the indicated mode. 
  757.  
  758. \Xi{\kwd{eof(}<filehandle>\kwd{)}}
  759. Returns 1 if the next read will return end of file, or if the file is
  760. not open. 
  761.  
  762. \Xi{\kwd{eof}}
  763. Returns the eof status for the last file read.
  764.  
  765. \Xi{\kwd{eof( )}}
  766. Indicates eof on the pseudo file formed of the files listed on the
  767. command line. 
  768.  
  769. \Xi{\kwd{fcntl(}<filehandle>\kwd{,}<function>\kwd{,}|\$|<var>\kwd{)}}
  770. Implements the {\it fcntl\/}(2) function. This function has non-standard
  771. return values. See the manual for details. 
  772.  
  773. \Xi{\kwd{fileno(}<filehandle>\kwd{)}*}
  774. Returns the file descriptor for a given (open) file.
  775.  
  776. \Xi{\kwd{flock(}<filehandle>\kwd{,}<operation>\kwd{)}}
  777. Calls {\it flock\/}(2) on the file. <operation> adds from 1 (shared), 2
  778. (exclusive), 4 (non-blocking) or 8 (unlock). 
  779.  
  780.  
  781. \Xi{\kwd{getc}[\kwd{(}<filehandle>\kwd{)}*]}
  782. Yields the next character from the file, or |""| on EOF. If
  783. <filehandle> is omitted, reads from |STDIN|. 
  784.  
  785. \Xi{\kwd{ioctl(}<filehandle>\kwd{,}<function>\kwd{,}|\$|<var>\kwd{)}}
  786. performs {\it ioctl}(2) on the file. This function has non-standard
  787. return values. See the manual for details. 
  788.  
  789. \Xi{\kwd{open(}<filehandle>[\kwd{,}<filename>]\kwd{)}}
  790. Opens a file and associates it with <filehandle>. If <filename> is
  791. omitted, the scalar variable of the same name as the <filehandle> must
  792. contain the filename.
  793.  
  794. The following filename conventions apply when opening a file.
  795.  
  796. \begin{enum}{2cm}
  797. \Xi{|"|<file>|"|} open <file> for input. Also |"<|<file>|"|.
  798.  
  799. \Xi{|">|<file>|"|} open <file> for output, creating it if necessary.
  800.  
  801. \Xi{|">>|<file>|"|} open <file> in append mode.
  802.  
  803. \Xi{|"+>|<file>|"|} open <file> with read/write access.
  804.  
  805. \Xi{|"\||<cmd>|"|} opens a pipe to command <cmd>.
  806.  
  807. \Xi{|"|<cmd>|\|"|} opens a pipe from command <cmd>.
  808. \end{enum}
  809.  
  810. <file> may be |&|<filehnd> in which case the new file handle is
  811. connected to the (previously opened) filehandle <filehnd>.
  812.  
  813. \kwd{open} 
  814. returns 1 upon success, \kwd{undef} otherwise, except for pipes. The
  815. parentheses may be omitted, if only a <filehandle> is specified.
  816.  
  817. \Xi{\kwd{pipe(}<readhandle>\kwd{,}<writehandle>\kwd{)}}
  818. Returns a pair of connected pipes.
  819.  
  820. \Xi{\kwd{print}[\kwd{(}[<filehandle>]<list>\dag\kwd{)}*]}
  821. Prints a string or a comma-separated list of strings. If <filehandle>
  822. is omitted, prints by default to standard output (or to the last
  823. selected output channel - see \kwd{select}).  
  824.  
  825. \Xi{\kwd{printf}[\kwd{(}[<filehandle>] <list>\kwd{)}*]}
  826. Equivalent to \kwd{print} <filehandle> \kwd {sprintf(}<list>\kwd{)}.
  827.  
  828. \Xi{\kwd{read(}<filehandle>\kwd{,}|\$|<var>\kwd{,}<length>[\kwd{,}<offset>]\kwd{)}}
  829. Read <length> binary bytes from the file into the variable at
  830. <offset>. Returns number of bytes actually read. 
  831.  
  832. \Xi{\kwd{seek(}<filehandle>\kwd{,}<position>\kwd{,}<whence>\kwd{)}}
  833. Arbitrarily positions the file. Returns 1 upon success, 0 otherwise.
  834.  
  835. \Xi{\kwd{select}[\kwd{(}<filehandle>\kwd{)}]}
  836. Returns the currently selected filehandle. 
  837. Sets the current default filehandle for output operations if
  838. <filehandle> is supplied.
  839.  
  840. \Xi{\kwd{select(}<rbits>\kwd{,}<wbits>\kwd{,}<nbits>\kwd{,}<timeout>\kwd{)}}
  841. Performs a {\it select\/}(2) system call with the same parameters.
  842.  
  843. \Xi{\kwd{sprintf(}<format>\kwd{,}<list>\kwd{)}}
  844. Returns a string formatted by (almost all of) the usual printf
  845. conventions. 
  846.  
  847. \Xi{\kwd{sysread(}<filehandle>\kwd{,}|\$|<var>\kwd{,}<length>[\kwd{,}<offset>]\kwd{)}}
  848. Reads <length> bytes into |$|<var> at <offset>.
  849.  
  850. \Xi{\kwd{syswrite(}<filehandle>\kwd{,}<scalar>\kwd{,}<length>[\kwd{,}<offset>]\kwd{)}}
  851. Writes <length> bytes from <scalar> at <offset>.
  852.  
  853. \Xi{\kwd{tell}[\kwd{(}<filehandle>\kwd{)}]*}
  854. Returns the current file position for the file. If <filehandle> is
  855. omitted, assumes the file last read. 
  856.  
  857. \Xi{\kwd{write}[\kwd{(}<filehandle>\kwd{)}]*}
  858. Writes a formatted record to the specified file, using the format
  859. associated with that file. See ``Formats''. 
  860.  
  861. \end{enum}
  862.  
  863. \makeuppage
  864.  
  865. \section{Search and replace functions}
  866.  
  867. \begin{enum}{1cm}
  868.  
  869. \catcode`\~=\other
  870.  
  871. \Xi{[<expr> |=~|] [\kwd{m}]|/|<pattern>|/|[\kwd{g}][\kwd{i}][\kwd{o}]}
  872. Searches <expr> (default: |$_|) for a pattern. If you prepend an
  873. \kwd{m} you can use almost any pair of characters as delimiters. If
  874. used in array context, an array is returned consisting of the
  875. subexpressions matched by the parentheses in pattern, i.e.
  876. |($1,$2,$3,...)|.
  877. \\
  878. Optional modifiers: \kwd{g} matches as many times as possible; \kwd{i}
  879. searches in a case-insensitive manner; \kwd{o} interpolates variables
  880. only once.
  881. \\
  882. If <pattern> is empty, the most recent pattern from a
  883. previous match or replacement is used.
  884. \\
  885. With \kwd{g} the match can be used as an iterator in scalar context.
  886.  
  887. \Xi{|?|<pattern>|?|}
  888. This is just like the |/|<pattern>|/| search, except that it matches
  889. only once between calls to the reset operator. If <pattern> is empty,
  890. the most recent pattern from a previous match or replacement is used.
  891.  
  892. \Xi{[|\$|<var> |=~|] \kwd{s}|/|<pattern>|/|<replacement>|/|[\kwd{g}][\kwd{i}][\kwd{e}][\kwd{o}]}
  893. Searches a string for a pattern, and if found, replaces that pattern
  894. with the replacement text and returns the number of substitutions
  895. made. Otherwise it returns false. 
  896. \\
  897. Optional modifiers: \kwd{g} replaces all occurrences of the pattern;
  898. \kwd{e} interprets the replacement string as an expression; \kwd{i}
  899. and \kwd{o} as with |/|<pattern>|/| matching. Almost any delimiter may
  900. replace the slashes; if single quotes are used, no interpretation is
  901. done on the replacement string.
  902. \\
  903. If bracketing quotes are used, <pattern> and <replacement> 
  904. may have their own delimiters, e.g. |s(foo)[bar]|.
  905. \\
  906. If <pattern> is empty, the most recent pattern from a previous match or replacement is used.
  907.  
  908. \Xi{\kwd{study}[\kwd{(}|\$|<var>\dag\kwd{)}*]}
  909. Study the contents of |$|<var> in anticipation of doing many pattern
  910. matches on the contents before it is next modified.
  911.  
  912. \Xi{[|\$|<var> |=~|] \kwd{tr}|/|<searchlist>|/|<replacementlist>|/|[\kwd{c}][\kwd{d}][\kwd{s}]}
  913. Translates all occurrences of the characters found in the search list
  914. with the corresponding character in the replacement list. It returns
  915. the number of characters replaced. \kwd{y} may be used instead of \kwd{tr}. 
  916. \\
  917. Optional modifiers: \kwd{c} complements the <searchlist>; \kwd{d}
  918. deletes all characters not found in <searchlist>; \kwd{s} squeezes all
  919. sequences of characters that are translated into the same target
  920. character into one occurrence of this character.
  921.  
  922. \end{enum}
  923.  
  924. \makeupspace{1cm}
  925.  
  926. \section{System interaction} 
  927.  
  928. \begin{enum}{1cm}
  929.  
  930. \Xi{\kwd{alarm(}<expr>\kwd{)}*}
  931. Schedules a |SIGALRM| to be delivered after <expr> seconds. 
  932.  
  933. \Xi{\kwd{chdir} [\kwd{(}<expr>\kwd{)}*]}
  934. Changes the working directory, |$ENV{"HOME"}| if <expr> is omitted.
  935.  
  936. \Xi{\kwd{chroot(}<filename>\dag\kwd{)}*}
  937. Changes the root directory for the process and its children.
  938.  
  939. \Xi{\kwd{die}[\kwd{(}<list>\kwd{)}*]}
  940. Prints the value of <list> to |STDERR| and exits with the current
  941. value of |$!| (errno). If |$!| is 0, exits with the value of |($? >> 8)|.
  942. If |($? >> 8)| is 0, exits with 255. <list> defaults to
  943. |"Died."|.
  944.  
  945. \Xi{\kwd{exec(}<list>\kwd{)}*}
  946. Executes the system command in <list>; does not return.
  947.  
  948. \Xi{\kwd{exit(}<expr>\kwd{)}*}
  949. Exits immediately with the value of |EXPR|.
  950.  
  951. \Xi{\kwd{fork}}
  952. Does a {\it fork\/}(2) system call. Returns the child pid to the parent
  953. process and zero to the child process. 
  954.  
  955. \Xi{\kwd{getlogin}}
  956. Returns the current login name as known by the system.
  957.  
  958. \Xi{\kwd{getpgrp}[\kwd{(}<pid>\kwd{)}*]}
  959. Returns the process group for process <pid> (0, or omitted,  means the
  960. current process). 
  961.  
  962. \Xi{\kwd{getppid}}
  963. Returns the process id of the parent process.
  964.  
  965. \Xi{\kwd{getpriority(}<which>\kwd{,}<who>\kwd{)}}
  966. Returns the current priority for a process, process group, or user.
  967.  
  968. \Xi{\kwd{kill(}<list>\kwd{)}*}
  969. Sends a signal to a list of processes. The first element of the list
  970. must be the signal to send (numeric, or its name as a string). 
  971.  
  972. \Xi{\kwd{setpgrp(}<pid>\kwd{,}<pgrp>\kwd{)}}
  973. Sets the process group for the <pid> (0 = current process).
  974.  
  975. \Xi{\kwd{setpriority(}<which>\kwd{,}<who>\kwd{,}<prio>\kwd{)}}
  976. Sets the current priority for a process, process group, or a user.
  977.  
  978. \Xi{\kwd{sleep}[\kwd{(}<expr>\kwd{)}*]}
  979. Causes the script to sleep for <expr> seconds, or forever if no
  980. <expr>. Returns the number of seconds actually slept. 
  981.  
  982. \Xi{\kwd{syscall(}<list>\kwd{)}*}
  983. Calls the system call specified in the first element of the list,
  984. passing the rest of the list as arguments to the call. 
  985.  
  986. \Xi{\kwd{system(}<list>\kwd{)}*}
  987. Does exactly the same thing as \kwd{exec }<list> except that a fork is
  988. done first, and the parent process waits for the child process to complete. 
  989.  
  990. \Xi{\kwd{times}}
  991. Returns a 4-element array (\$user, \$system, \$cuser, \$csystem) giving
  992. the user and system times, in seconds, for this process and the
  993. children of this process.  
  994.  
  995. \Xi{\kwd{umask}[\kwd{(}<expr>\kwd{)}*]}
  996. Sets the umask for the process and returns the old one. If <expr> is
  997. omitted, returns current umask value. 
  998.  
  999. \Xi{\kwd{wait}}
  1000. Waits for a child process to terminate and returns the pid of the
  1001. deceased process (-1 if none). The status is returned in |$?|. 
  1002.  
  1003. \Xi{\kwd{waitpid(}<pid>\kwd{,}<flags>\kwd{)}}
  1004. Performs the same function as the corresponding system call.
  1005.  
  1006. \Xi{\kwd{warn(}<list>\kwd{)}*}
  1007. Prints the message on |STDERR| like \kwd{die}, but doesn't exit.
  1008.  
  1009. \end{enum}
  1010.  
  1011. \makeuppage
  1012.  
  1013. \section{Networking} 
  1014.  
  1015. \begin{enum}{1cm}
  1016.  
  1017. \Xi{\kwd{accept(}<newsocket>\kwd{,}<genericsocket>\kwd{)}}
  1018. Accepts a new socket.
  1019.  
  1020. \Xi{\kwd{bind(}<socket>\kwd{,}<name>\kwd{)}}
  1021. Binds the <name> to the <socket>.
  1022.  
  1023. \Xi{\kwd{connect(}<socket>\kwd{,}<name>\kwd{)}}
  1024. Connects the <name> to the <socket>.
  1025.  
  1026. \Xi{\kwd{getpeername(}<socket>\kwd{)}}
  1027. Returns the socket address of the other end of the <socket>.
  1028.  
  1029. \Xi{\kwd{getsockname(}<socket>\kwd{)}}
  1030. Returns the name of the socket.
  1031.  
  1032. \Xi{\kwd{getsockopt(}<socket>\kwd{,}<level>\kwd{,}<optname>\kwd{)}}
  1033. Returns the socket options.
  1034.  
  1035. \Xi{\kwd{listen(}<socket>\kwd{,}<queuesize>\kwd{)}}
  1036. Starts listening on the specified <socket>.
  1037.  
  1038. \Xi{\kwd{recv(}<socket>\kwd{,}<scalar>\kwd{,}<length>\kwd{,}<flags>\kwd{)}}
  1039. Receives a message on <socket>.
  1040.  
  1041. \Xi{\kwd{send(}<socket>\kwd{,}<msg>\kwd{,}<FLAGS[>\kwd{,}<to>]\kwd{)}}
  1042. Sends a message on the <socket>.
  1043.  
  1044. \Xi{\kwd{setsockopt(}<socket>\kwd{,}<level>\kwd{,}<optname>\kwd{,}<optval>\kwd{)}}
  1045. Sets the requested socket option.
  1046.  
  1047. \Xi{\kwd{shutdown(}<socket>\kwd{,}<how>\kwd{)}}
  1048. Shuts down a <socket>.
  1049.  
  1050. \Xi{\kwd{socket(}<socket>\kwd{,}<domain>\kwd{,}<type>\kwd{,}<protocol>\kwd{)}}
  1051. Creates a <socket> in <domain> with <type> and <protocol>.
  1052.  
  1053. \Xi{\kwd{socketpair(}<socket1>\kwd{,}<socket2>\kwd{,}<domain>\kwd{,}<type>\kwd{,}<protocol>\kwd{)}}
  1054. As socket, but creates a pair of bi-directional sockets.
  1055.  
  1056. \end{enum}
  1057.  
  1058. \makeupspace{1cm}
  1059.  
  1060. \section{SystemV IPC} 
  1061.  
  1062. The following functions all perform the same action as the
  1063. corresponding system calls.
  1064.  
  1065. \kwd{msgctl(}<id>\kwd{,}<cmd>\kwd{,}<args>\kwd{)} \\
  1066. \kwd{msgget(}<key>\kwd{,}<flags>\kwd{)} \\
  1067. \kwd{msgsnd(}<id>\kwd{,}<msg>\kwd{,}<flags>\kwd{)} \\
  1068. \kwd{msgrcv(}<id>\kwd{,}\$<var>\kwd{,}<size>\kwd{,}<type>\kwd{,}<flags>\kwd{)} \\
  1069. \kwd{semctl(}<id>\kwd{,}<semnum>\kwd{,}<cmd>\kwd{,}<arg>\kwd{)} \\
  1070. \kwd{semget(}<key>\kwd{,}<nsems>\kwd{,}<size>\kwd{,}<flags>\kwd{)} \\
  1071. \kwd{semop(}<key>\kwd{,}...\kwd{)} \\
  1072. \kwd{shmctl(}<id>\kwd{,}<cmd>\kwd{,}<arg>\kwd{)} \\
  1073. \kwd{shmget(}<key>\kwd{,}<size>\kwd{,}<flags>\kwd{)} \\
  1074. \kwd{shmread(}<id>\kwd{,}\$<var>\kwd{,}<pos>\kwd{,}<size>\kwd{)} \\
  1075. \kwd{shmwrite(}<id>\kwd{,}<string>\kwd{,}<pos>\kwd{,}<size>\kwd{)}
  1076.  
  1077. \makeuppage
  1078.  
  1079. \section{Miscellaneous} 
  1080.  
  1081. \begin{enum}{1cm}
  1082.  
  1083. \Xi{\kwd{caller}[\kwd{(}<expr>\kwd{)}]}
  1084. Returns an array (\$package,\$file,\$line,...) for a specific subroutine
  1085. call. ``|caller|'' returns this info for the current subroutine,
  1086. ``|caller(1)|'' for the caller of this subroutine etc..  
  1087.  
  1088. \Xi{\kwd{defined(}<expr>\kwd{)}*}
  1089. Tests whether the lvalue <expr> has a real value.
  1090.  
  1091. \Xi{\kwd{dump} [<label>]}
  1092. Immediate core dump. When reincarnated, starts at <label>.
  1093.  
  1094. \Xi{\kwd{local(}<list>\kwd{)}}
  1095. Creates a scope for the listed variables local to the enclosing block,
  1096. subroutine or eval. 
  1097.  
  1098. \Xi{\kwd{package} <name>}
  1099. Designates the remainder of the current block as a package.
  1100.  
  1101. \Xi{\kwd{require(}\oEXPR\kwd{)}*}
  1102. Includes the specified file from the perl library. Does not include
  1103. more than once, and yields a fatal error if the file does not include OK. 
  1104.  
  1105. \Xi{\kwd{reset} [\kwd{(}<expr>\kwd{)}*]}
  1106. Resets |??| searches so that they work again. <expr> is a list of
  1107. single letters. All variables and arrays beginning with one of those
  1108. letters are reset to their pristine state.  Only affects the current
  1109. package.
  1110.  
  1111. \Xi{\kwd{scalar(}<expr>\kwd{)}}
  1112. Forces evaluation of <expr> in scalar context.
  1113.  
  1114. \Xi{\kwd{sub} <name> \{ <expr> |;| ... \}}
  1115. Designates <name> as a subroutine. Parameters are passed by reference
  1116. as array |@_|. Returns the value of the last expression evaluated. 
  1117.  
  1118. \Xi{\kwd{undef}[\kwd{(}<lvalue>\kwd{)}*]}
  1119. Undefines the <lvalue>. Always returns the undefined value.
  1120.  
  1121. \Xi{\kwd{wantarray}}
  1122. Returns true if the current context expects an array value.
  1123.  
  1124. \end{enum}
  1125.  
  1126.  
  1127. \section{Formats} 
  1128.  
  1129. \kwd{format} [<name>] |=| \\
  1130. <formlist> \\
  1131. |.|
  1132.  
  1133. <formlist> pictures the lines, and contains the arguments which will
  1134. give values to the fields in the lines. Picture fields are:
  1135.  
  1136. |  @<<<...  | left adjusted field, repeat the |<| to denote the desired
  1137. width; \\
  1138. |  @>>>...  | right adjusted field; \\
  1139. |  @|\|\|\||...  | centered field; \\
  1140. |  @#.##... | numeric format with implied decimal point; \\
  1141. |  @*       | a multi-line field.
  1142.  
  1143. Use \^ instead of |@| for multi-line block filling.
  1144.  
  1145. Use |~| at the beginning of a line to suppress unwanted empty lines.
  1146.  
  1147. Use |~~| at the beginning of a line to have this format line repeated
  1148. until all fields are exhausted. 
  1149.  
  1150. Use |$-| to zero to force a page break.
  1151.  
  1152. See also |$|\^, |$~|, |$-| and |$=| in section ``Special Variables''.
  1153.  
  1154.  
  1155. \section{Info from system files} 
  1156. See the manual about return values in scalar context.
  1157.  
  1158. {\large\sl passwd} \\
  1159. Returns (\$name, \$passwd, \$uid, \$gid, \$quota, \$comment, \$gcos, \$dir, \$shell).
  1160.  
  1161. \begin{enum}{6cm}
  1162.  
  1163. \Xi{\kwd{endpwent}}    Ends lookup processing.
  1164.  
  1165. \Xi{\kwd{getpwent}}    Gets next info.
  1166.  
  1167. \Xi{\kwd{getpwnam(}<name>\kwd{)}}    Gets info by name. 
  1168.  
  1169. \Xi{\kwd{getpwuid(}<uid>\kwd{)}}    Gets info by uid.
  1170.  
  1171. \Xi{\kwd{setpwent}}    Resets lookup processing.
  1172.  
  1173. \end{enum}
  1174.  
  1175. {\vskip6pt\large\sl group} \\
  1176. Returns (\$name, \$passwd, \$gid, \$members).
  1177.  
  1178. \begin{enum}{6cm}
  1179.  
  1180. \Xi{\kwd{endgrent}}    Ends lookup processing.
  1181.  
  1182. \Xi{\kwd{getgrgid(}<gid>\kwd{)}}    Gets info by group id. 
  1183.  
  1184. \Xi{\kwd{getgrnam(}<name>\kwd{)}}    Gets info by name.
  1185.  
  1186. \Xi{\kwd{getgrent}}    Gets next info.
  1187.  
  1188. \Xi{\kwd{setgrent}}    Resets lookup processing.
  1189.  
  1190. \end{enum}
  1191.  
  1192. {\vskip6pt\large\sl hosts} \\
  1193. Returns (\$name, \$aliases, \$addrtype, \$length, @addrs).
  1194.  
  1195. \begin{enum}{6cm}
  1196.  
  1197. \Xi{\kwd{endhostent}}    Ends lookup processing.
  1198.  
  1199. \Xi{\kwd{gethostbyaddr(}<addr>\kwd{,}<addrtype>\kwd{)}}    Gets info by address.
  1200.  
  1201. \Xi{\kwd{gethostbyname(}<name>\kwd{)}}    Gets info by name.
  1202.  
  1203. \Xi{\kwd{gethostent}}    Gets next info.
  1204.  
  1205. \Xi{\kwd{sethostent(}<stayopen>\kwd{)}}    Resets lookup processing.
  1206.  
  1207. \end{enum}
  1208.  
  1209. {\vskip6pt\large\sl networks} \\
  1210. Returns (\$name, \$aliases, \$addrtype, \$net).
  1211.  
  1212. \begin{enum}{6cm}
  1213.  
  1214. \Xi{\kwd{endnetent}}    Ends lookup processing.
  1215.  
  1216. \Xi{\kwd{getnetbyaddr(}<addr>\kwd{,}<type>\kwd{)}}    Gets info by address and type.
  1217.  
  1218. \Xi{\kwd{getnetbyname(}<name>\kwd{)}}    Gets info by name.
  1219.  
  1220. \Xi{\kwd{getnetent}}    Gets next info.
  1221.  
  1222. \Xi{\kwd{setnetent(}<stayopen>\kwd{)}}    Resets lookup processing.
  1223.  
  1224. \end{enum}
  1225.  
  1226. {\vskip6pt\large\sl services} \\
  1227. Returns (\$name, \$aliases, \$port, \$proto).
  1228.  
  1229. \begin{enum}{6cm}
  1230.  
  1231. \Xi{\kwd{endservent}}    Ends lookup processing.
  1232.  
  1233. \Xi{\kwd{getservbyname(}<name>\kwd{, }<proto>\kwd{)}}    Gets info by name. 
  1234.  
  1235. \Xi{\kwd{getservbyport(}<port>\kwd{, }<proto>\kwd{)}}    Gets info by port.
  1236.  
  1237. \Xi{\kwd{getservent}}    Gets next info.
  1238.  
  1239. \Xi{\kwd{setservent(}<stayopen>\kwd{)}}    Resets lookup processing.
  1240.  
  1241. \end{enum}
  1242.  
  1243. {\vskip6pt\large\sl protocols} \\
  1244.  
  1245. Returns (\$name, \$aliases, \$proto).
  1246.  
  1247. \begin{enum}{6cm}
  1248.  
  1249. \Xi{\kwd{endprotoent}}    Ends lookup processing.
  1250.  
  1251. \Xi{\kwd{getprotobyname(}<name>\kwd{)}}    Gets info by name.
  1252.  
  1253. \Xi{\kwd{getprotobynumber(}<number>\kwd{)}}    Gets info by number.
  1254.  
  1255. \Xi{\kwd{getprotoent}}    Gets next info.
  1256.  
  1257. \Xi{\kwd{setprotoent(}<stayopen>\kwd{)}}    Resets lookup processing.
  1258.  
  1259. \end{enum}
  1260.  
  1261.  
  1262. \section{Regular expressions} 
  1263.  
  1264. Each character matches itself, unless it is one of the special
  1265. characters |+?.*()[]{}|\||\|.
  1266.  
  1267. \begin{enum}{1cm}
  1268.  
  1269. \Xj{|.|}
  1270. matches an arbitrary character, but not a newline.
  1271.  
  1272. \Xj{|(|\ldots|)|}
  1273. groups a series of pattern elements to a single element.
  1274.  
  1275. \Xj{|+|}
  1276. matches the preceding pattern element one or more times.
  1277.  
  1278. \Xj{|?|}
  1279. matches zero or one times.
  1280.  
  1281. \Xj{|*|}
  1282. matches zero or more times.
  1283.  
  1284. \Xj{\{<n>|,|<m>\}}
  1285. denotes the minimum <n> and maximum <m> match count. |{|<n>|}| means
  1286. exactly <n> times; |{|<n>|,}| means at least <n> times. 
  1287.  
  1288. \Xj{|\char`\[|\ldots|\char`\]|}
  1289. denotes a class of characters to match. |[|\^\ldots|]| negates the class.
  1290.  
  1291. \Xj{|(|\ldots\|\ldots\|\ldots|)|}
  1292. matches one of the alternatives.
  1293.  
  1294. \end{enum}
  1295.  
  1296. Non-alphanumerics can be escaped from their special meaning using a
  1297. |\|.
  1298.  
  1299. \begin{enum}{1cm}
  1300.  
  1301. \Xj{|\char`\\w|}
  1302. matches alphanumeric, including ``|_|'', |\W| matches non-alphanumeric.
  1303.  
  1304. \Xj{|\char`\\b|}
  1305. matches word boundaries, |\B| matches non-boundaries.
  1306.  
  1307. \Xj{|\char`\\s|}
  1308. matches whitespace, |\S| matches non-whitespace.
  1309.  
  1310. \Xj{|\char`\\d|}
  1311. matches numeric, |\D| matches non-numeric.
  1312.  
  1313. \Xj{|\char`\\n|, |\char`\\r|, |\char`\\f|, |\char`\\t| etc.} 
  1314. have their usual meaning.
  1315.  
  1316. \Xj{|\char`\\w|, |\char`\\s| and |\char`\\d|}
  1317.  may be used within character classes, |\b| denotes backspace in this context.
  1318.  
  1319. \Xj{|\char`\\1|\ldots|\char`\\9|}
  1320. refer to matched sub-expressions, grouped with |()|, inside
  1321. the match. 
  1322.  
  1323. \Xj{|\char`\\10|}
  1324. and up can also be used if the pattern
  1325. matches that many sub-expressions. 
  1326.  
  1327. \end{enum}
  1328.  
  1329. See also |$1|\ldots|$9|, |$+|, |$&|, |$`| and |$'| in section ``Special
  1330. Variables''.
  1331.  
  1332.  
  1333.  
  1334. \section{Special variables} 
  1335.  
  1336. The following variables are global and should be localized in subroutines:
  1337.  
  1338. \begin{enum}{1cm}
  1339.  
  1340. \Xi{|\char`\$\char`\_|}
  1341. The default input and pattern-searching space.
  1342.  
  1343. \Xi{|\char`\$\char`\.|}
  1344. The current input line number of the last filehandle that was read.
  1345.  
  1346. \Xi{|\char`\$\char`\/|}
  1347. The input record separator, newline by default. May be multi-character.
  1348.  
  1349. \Xi{|\char`\$\char`\,|}
  1350. The output field separator for the print operator.
  1351.  
  1352. \Xi{|\char`\$\char`\"|}
  1353. The separator which joins elements of arrays interpolated in strings.
  1354.  
  1355. \Xi{|\char`\$\char`\\|}
  1356. The output record separator for the print operator.
  1357.  
  1358. \Xi{|\char`\$\char`\#|}
  1359. The output format for printed numbers. Initial value is ``|%.20g|''.
  1360.  
  1361. \Xi{|\char`\$\char`\*|}
  1362. Set to 1 to do multiline matching within a string, 0 to assume strings
  1363. contain a single line. Default is 0. 
  1364.  
  1365. \Xi{|\char`\$\char`\?|}
  1366. The status returned by the last |`|<command>|`|, pipe close or
  1367. \kwd{system} operator. 
  1368.  
  1369. \Xi{|\char`\$\char`\]|}
  1370. The perl version string (as displayed with |perl -v|), or version number.
  1371.  
  1372. \Xi{|\char`\$\char`\[|}
  1373. The index of the first element in an array, and of the first character
  1374. in a substring. Default is 0. 
  1375.  
  1376. \Xi{|\char`\$\char`\;|}
  1377. The subscript separator for multi-dimensional array emulation. Default
  1378. is |"\034"|. 
  1379.  
  1380. \Xi{|\char`\$\char`\!|}
  1381. If used in a numeric context, yields the current value of errno. If
  1382. used in a string context, yields the corresponding error string. 
  1383.  
  1384. \Xi{|\char`\$\char`\@|}
  1385. The perl error message from the last eval or \kwd{do} <expr> command.
  1386.  
  1387. \Xi{|\char`\$\char`\:|}
  1388. The set of characters after which a string may be broken to fill
  1389. continuation fields (starting with ``|^|'') in a format. 
  1390.  
  1391. \Xi{|\char`\$\char`\0|}
  1392. The name of the file containing the perl script being executed. May be
  1393. assigned to. 
  1394.  
  1395. \Xi{|\char`\$\char`\$|}
  1396. The process number of the perl running this script. Altered (in the
  1397. child process) by \kwd{fork}. 
  1398.  
  1399. \Xi{|\char`\$\char`\<|}
  1400. The real uid of this process.
  1401.  
  1402. \Xi{|\char`\$\char`\>|}
  1403. The effective uid of this process. 
  1404.  
  1405. \Xi{|\char`\$\char`\(|}
  1406. The real gid of this process.
  1407.  
  1408. \Xi{|\char`\$\char`\)|}
  1409. The effective gid of this process.
  1410.  
  1411. \Xi{|\char`\$\char`\^D|}
  1412. The debug flags as passed to perl using |-D| .
  1413.  
  1414. \Xi{|\char`\$\char`\^F|}
  1415. The highest system file descriptor, ordinarily 2.
  1416.  
  1417. \Xi{|\char`\${\char`\^}I|}
  1418. In-place edit extension as passed to perl using |-i| .
  1419.  
  1420. \Xi{|\char`\$\char`\^L|}
  1421. Formfeed character used in formats.
  1422.  
  1423. \Xi{|\char`\$\char`\^P|}
  1424. Internal debugging flag.
  1425.  
  1426. \Xi{|\char`\$\char`\^T|}
  1427. The time (as delivered by \kwd{time}) when the program started. This
  1428. value is used by the file test operators ``|-M|'', ``|-A|'' and
  1429. ``|-C|''.
  1430.  
  1431. \Xi{|\char`\$\char`\^W|}
  1432. The value if the |-w| option as passed to perl.
  1433.  
  1434. \Xi{|\char`\$\char`\^X|}
  1435. The name by which this perl was invoked.
  1436.  
  1437. \end{enum}
  1438.  
  1439. The following variables are context dependent and need not be
  1440. localized:
  1441.  
  1442. \begin{enum}{1cm}
  1443.  
  1444. \Xi{|\char`\$\char`\%|}
  1445. The current page number of the currently selected output channel.
  1446.  
  1447. \Xi{|\char`\$\char`\=|}
  1448. The page length of the current output channel. Default is 60 lines.
  1449.  
  1450. \Xi{|\char`\$\char`\-|}
  1451. The number of lines left on the page.
  1452.  
  1453. \Xi{|\char`\$\char`\~|}
  1454. The name of the current report format.
  1455.  
  1456. \Xi{|\char`\$\char`\^|}
  1457. The name of the current top-of-page format.
  1458.  
  1459. \Xi{|\char`\$\char`\||}
  1460. If set to nonzero, forces a flush after every write or print on the
  1461. currently selected output channel. Default is 0. 
  1462.  
  1463. \Xj{|\char`\$ARGV|}
  1464. The name of the current file when reading from |<>| .
  1465. \end{enum}
  1466.  
  1467. The following variables are always local to the current block:
  1468.  
  1469. \begin{enum}{1cm}
  1470.  
  1471. \Xi{|\char`\$\char`\&|}
  1472. The string matched by the last successful pattern match.
  1473.  
  1474. \Xi{|\char`\$\char`\`|}
  1475. The string preceding what was matched by the last successful match.
  1476.  
  1477. \Xi{|\char`\$\char`\'|}
  1478. The string following what was matched by the last successful match. 
  1479.  
  1480. \Xi{|\char`\$\char`\+|}
  1481. The last bracket matched by the last search pattern.
  1482.  
  1483. \Xi{\$|1|\ldots\$|9|\ldots}
  1484. Contains the subpattern from the corresponding set of parentheses in
  1485. the last pattern successfully matched.
  1486. |$10|\ldots and up are only available if the
  1487. match contained that many sub-expressions. 
  1488.  
  1489. \end{enum}
  1490.  
  1491.  
  1492.  
  1493.  
  1494. \section{Special arrays} 
  1495.  
  1496. \begin{enum}{1.5cm}
  1497.  
  1498. \Xi{|@ARGV|}
  1499. Contains the command line arguments for the script (not including the command name).
  1500.  
  1501. \Xi{|@INC|}
  1502. Contains the list of places to look for perl scripts to be evaluated
  1503. by the \kwd{do} <filename> and \kwd{require} commands. 
  1504.  
  1505. \Xi{|@\char`\_|}
  1506. Parameter array for subroutines. Also used by \kwd{split} if not in
  1507. array context. 
  1508.  
  1509. \Xi{|\char`\%ENV|}
  1510. Contains the current environment.
  1511.  
  1512. \Xi{|\char`\%INC|}
  1513. List of files that have been \kwd{require}d or \kwd{do}ne.
  1514.  
  1515. \Xi{|\char`\%SIG|}Used to set signal handlers for various signals.
  1516.  
  1517. \end{enum}
  1518.  
  1519.  
  1520. \section{The perl debugger} 
  1521.  
  1522. The perl symbolic debugger is invoked with |perl -d|.
  1523.  
  1524. \begin{enum}{2.5cm}
  1525.  
  1526. \Xi{|h|}
  1527. Prints out a help message.
  1528.  
  1529. \Xi{|T|}
  1530. Stack trace.
  1531.  
  1532. \Xi{|s|}
  1533. Single steps.
  1534.  
  1535. \Xi{|n|}
  1536. Single steps around subroutine call.
  1537.  
  1538. \Xi{|r|}
  1539. Returns from the current subroutine.
  1540.  
  1541. \Xi{|c| [<line>]}
  1542. Continues (until <line>, or another breakpoint or exit).
  1543.  
  1544. \Xi{\fbox{<ret>}}
  1545. Repeats last |s| or |n|.
  1546.  
  1547. \Xi{|l| [<range>]}
  1548. Lists a range of lines. <range> may be a number, start-end,
  1549. start+amount, or a subroutine name. If omitted, lists next window. 
  1550.  
  1551. \Xi{|f| <file>}
  1552. Switches to <file> and start listing it.
  1553.  
  1554. \Xi{|-|}
  1555. Lists previous window.
  1556.  
  1557. \Xi{|w|}
  1558. Lists window around current line.
  1559.  
  1560. \Xi{|l| <sub>}
  1561. Lists the named <sub>routine.
  1562.  
  1563. \Xi{|/|<pattern>|/|}
  1564. Forward search for <pattern>.
  1565.  
  1566. \Xi{|?|<pattern>|?|}
  1567. Backward search for <pattern>.
  1568.  
  1569. \Xi{|L|}
  1570. Lists lines that have breakpoints or actions.
  1571.  
  1572. \Xi{|S|}
  1573. List the names of all subroutines.
  1574.  
  1575. \Xi{|t|}
  1576. Toggles trace mode.
  1577.  
  1578. \Xi{|b| [<line> [<condition>]]}
  1579. Sets breakpoint at <line>, default: current line.
  1580.  
  1581. \Xi{|b| <subname> [<condition>]}
  1582. Sets breakpoint at the subroutine.
  1583.  
  1584. \Xi{|S|}
  1585. Lists names of all subroutines.
  1586.  
  1587. \Xi{|d| [<line>]}
  1588. Deletes breakpoint at the given line.
  1589.  
  1590. \Xi{|D|}
  1591. Deletes all breakpoints.
  1592.  
  1593. \Xi{|a| <line command>}
  1594. Sets an action for line.
  1595.  
  1596. \Xi{|A|}
  1597. Deletes all line actions.
  1598.  
  1599. \Xi{|\char`\<| <command>}
  1600. Sets an action to be executed before every debugger prompt.
  1601.  
  1602. \Xi{|\char`\>| <command>}
  1603. Sets an action to be executed before every |s|, |c| or |n| command.
  1604.  
  1605. \Xi{|V| [<package> [<vars>] ]}
  1606. Lists all variables in a package. Default package is main.
  1607.  
  1608. \Xi{|X| [<vars>]}
  1609. Like |V|, but assumes current package.
  1610.  
  1611. \Xi{|!| [ [-]<number>]}
  1612. Redo a debugging command. Default is previous command.
  1613.  
  1614. \Xi{|H| [-<number>]}
  1615. Displays the last -<number> commands of more than one letter.
  1616.  
  1617. \Xi{|q|}
  1618. Quits. You may also use your \fbox{<eof>} character.
  1619.  
  1620. \Xi{<command>}
  1621. Executes <command> as a perl statement.
  1622.  
  1623. \Xi{|p| \oEXPR}
  1624. Prints <expr>.
  1625.  
  1626. \Xi{|=|< >[<alias value>]}
  1627. Sets alias, or lists current aliases.
  1628.  
  1629. \end{enum}
  1630.  
  1631. \makeuppage
  1632.  
  1633. \section{Environment variables} 
  1634.  
  1635. Perl uses the following environment variables.
  1636.  
  1637. \begin{enum}{1.5cm}
  1638.  
  1639. \Xi{|HOME|}
  1640. Used if \kwd{chdir} has no argument.
  1641.  
  1642. \Xi{|LOGDIR|}
  1643. Used if \kwd{chdir} has no argument and |HOME| is not set.
  1644.  
  1645. \Xi{|PATH|}
  1646. Used in executing subprocesses, and in finding the perl script if |-S|
  1647. is used.
  1648.  
  1649. \Xi{|PERLLIB|}
  1650. A colon-separated list of directories to look for perl library files
  1651. before looking in the standard library and the current directory.
  1652.  
  1653. \Xi{|PERLDB|}
  1654. The command to get the debugger code. Defaults to 
  1655. \hbox{|require 'perldb.pl'|}. 
  1656.  
  1657. \end{enum}
  1658.  
  1659. \makeupspace{1cm}
  1660.  
  1661. \unnumbered{Notes}
  1662. \vfill
  1663. \makebox[\textwidth]{Perl Reference Guide Revision \refrev \hfill
  1664. \copyright 1989,1993 Johan Vromans}
  1665.  
  1666.  
  1667. \end{document}
  1668.