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-4 < prev    next >
Encoding:
GNU Info File  |  1994-07-08  |  49.3 KB  |  1,197 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: Search and Replace Functions,  Next: System Interaction,  Prev: Input/Output,  Up: Commands
  32.  
  33. Search and Replace Functions
  34. ============================
  35.  
  36. m/PATTERN/gio
  37. /PATTERN/gio
  38.      Searches a string for a pattern match, and returns true (1) or
  39.      false ('').  If no string is specified via the `=~' or `!~'
  40.      operator, the `$_' string is searched.  (The string specified with
  41.      `=~' need not be an lvalue--it may be the result of an expression
  42.      evaluation, but remember the `=~' binds rather tightly.) *Note
  43.      Regular Expressions::, for more info.
  44.  
  45.      If `/' is the delimiter then the initial `m' is optional.  With
  46.      the `m' you can use any pair of non-alphanumeric characters as
  47.      delimiters.  This is particularly useful for matching Unix path
  48.      names that contain `/'.  If the final delimiter is followed by the
  49.      optional letter `i', the matching is done in a case-insensitive
  50.      manner.  PATTERN may contain references to scalar variables, which
  51.      will be interpolated (and the pattern recompiled) every time the
  52.      pattern search is evaluated.  (Note that `$)' and `$|' may not be
  53.      interpolated because they look like end-of-string tests.)  If you
  54.      want such a pattern to be compiled only once, add an `o' after the
  55.      trailing delimiter.  This avoids expensive run-time
  56.      recompilations, and is useful when the value you are interpolating
  57.      won't change over the life of the script.  If the PATTERN
  58.      evaluates to a null string, the most recent successful regular
  59.      expression is used instead.
  60.  
  61.      If used in a context that requires an array value, a pattern match
  62.      returns an array consisting of the subexpressions matched by the
  63.      parentheses in the pattern, i.e. `($1, $2, $3...)'.  It does *NOT*
  64.      actually set `$1', `$2', etc. in this case, nor does it set `$+',
  65.      `$`', `$&' or `$''.  If the match fails, a null array is returned.
  66.      If the match succeeds, but there were no parentheses, an array
  67.      value of (1) is returned.
  68.  
  69.      Examples:
  70.           open(tty, '/dev/tty');
  71.           <tty> =~ /^y/i && do foo(); # do foo if desired
  72.           
  73.           if (/Version: *([0-9.]*)/) { $version = $1; }
  74.           
  75.           next if m#^/usr/spool/uucp#;
  76.           
  77.           # poor man's grep
  78.           $arg = shift;
  79.           while (<>) {
  80.                   print if /$arg/o;   # compile only once
  81.           }
  82.           
  83.           if (($F1, $F2, $Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))
  84.  
  85.      This last example splits `$foo' into the first two words and the
  86.      remainder of the line, and assigns those three fields to `$F1',
  87.      `$F2' and `$Etc'.  The conditional is true if any variables were
  88.      assigned, i.e. if the pattern matched.
  89.  
  90.      The `g' modifier specifies global pattern matching--that is,
  91.      matching as many times as possible within the string.  How it
  92.      behaves depends on the context.  In an array context, it returns a
  93.      list of all the substrings matched by all the parentheses in the
  94.      regular expression.  If there are no parentheses, it returns a
  95.      list of all the matched strings, as if there were parentheses
  96.      around the whole pattern.  In a scalar context, it iterates
  97.      through the string, returning TRUE each time it matches, and FALSE
  98.      when it eventually runs out of matches.  (In other words, it
  99.      remembers where it left off last time and restarts the search at
  100.      that point.)  It presumes that you have not modified the string
  101.      since the last match.  Modifying the string between matches may
  102.      result in undefined behavior.  (You can actually get away with
  103.      in-place modifications via `substr()' that do not change the
  104.      length of the entire string.  In general, however, you should be
  105.      using `s///g' for such modifications.)  Examples:
  106.  
  107.           # array context
  108.           ($one,$five,$fifteen) = (`uptime` =~ /(\d+\.\d+)/g);
  109.           
  110.           # scalar context
  111.           $/ = ""; $* = 1;
  112.           while ($paragraph = <>) {
  113.               while ($paragraph =~ /[a-z]['")]*[.!?]+['")]*\s/g) {
  114.                   $sentences++;
  115.               }
  116.           }
  117.           print "$sentences\n";
  118.  
  119. ?PATTERN?
  120.      This is just like the `/pattern/' search, except that it matches
  121.      only once between calls to the `reset' operator.  This is a useful
  122.      optimization when you only want to see the first occurrence of
  123.      something in each file of a set of files, for instance.  Only `??'
  124.      patterns local to the current package are reset.
  125.  
  126. s/PATTERN/REPLACEMENT/gieo
  127.      Searches a string for a pattern, and if found, replaces that
  128.      pattern with the replacement text and returns the number of
  129.      substitutions made.  Otherwise it returns false (0).  The `g' is
  130.      optional, and if present, indicates that all occurrences of the
  131.      pattern are to be replaced.  The `i' is also optional, and if
  132.      present, indicates that matching is to be done in a
  133.      case-insensitive manner.  The `e' is likewise optional, and if
  134.      present, indicates that the replacement string is to be evaluated
  135.      as an expression rather than just as a double-quoted string.  Any
  136.      non-alphanumeric delimiter may replace the slashes; if single
  137.      quotes are used, no interpretation is done on the replacement
  138.      string (the `e' modifier overrides this, however); if backquotes
  139.      are used, the replacement string is a command to execute whose
  140.      output will be used as the actual replacement text.  If the
  141.      PATTERN is delimited by bracketing quotes, the REPLACEMENT has its
  142.      own pair of quotes, which may or may not be bracketing quotes,
  143.      e.g. `s(foo)(bar)' or `s<foo>/bar/'.  If no string is specified
  144.      via the `=~' or `!~' operator, the `$_' string is searched and
  145.      modified.  (The string specified with `=~' must be a scalar
  146.      variable, an array element, or an assignment to one of those, i.e.
  147.      an lvalue.)  If the pattern contains a `$' that looks like a
  148.      variable rather than an end-of-string test, the variable will be
  149.      interpolated into the pattern at run-time.  If you only want the
  150.      pattern compiled once the first time the variable is interpolated,
  151.      add an `o' at the end.  If the PATTERN evaluates to a null string,
  152.      the most recent successful regular expression is used instead.
  153.      *Note Regular Expressions::, for more info.  Examples:
  154.  
  155.           s/\bgreen\b/mauve/g;        # don't change wintergreen
  156.           
  157.           $path =~ s|/usr/bin|/usr/local/bin|;
  158.           
  159.           s/Login: $foo/Login: $bar/; # run-time pattern
  160.           
  161.           ($foo = $bar) =~ s/bar/foo/;
  162.           
  163.           $_ = 'abc123xyz';
  164.           s/\d+/$&*2/e;               # yields `abc246xyz'
  165.           s/\d+/sprintf("%5d",$&)/e;  # yields `abc  246xyz'
  166.           s/\w/$& x 2/eg;             # yields `aabbcc  224466xxyyzz'
  167.           
  168.           s/([^ ]*) *([^ ]*)/$2 $1/;  # reverse 1st two fields
  169.  
  170.      (Note the use of `$' instead of `\' in the last example.  *Note
  171.      Regular Expressions::.)
  172.  
  173. study(SCALAR)
  174. study SCALAR
  175. study
  176.      Takes extra time to study SCALAR (`$_' if unspecified) in
  177.      anticipation of doing many pattern matches on the string before it
  178.      is next modified.  This may or may not save time, depending on the
  179.      nature and number of patterns you are searching on, and on the
  180.      distribution of character frequencies in the string to be
  181.      searched--you probably want to compare runtimes with and without
  182.      it to see which runs faster.  Those loops which scan for many
  183.      short constant strings (including the constant parts of more
  184.      complex patterns) will benefit most.  You may have only one study
  185.      active at a time--if you study a different scalar the first is
  186.      "unstudied".  (The way study works is this: a linked list of every
  187.      character in the string to be searched is made, so we know, for
  188.      example, where all the `k' characters are.  From each search
  189.      string, the rarest character is selected, based on some static
  190.      frequency tables constructed from some C programs and English
  191.      text.  Only those places that contain this "rarest" character are
  192.      examined.)
  193.  
  194.      For example, here is a loop which inserts index producing entries
  195.      before any line containing a certain pattern:
  196.  
  197.           while (<>) {
  198.                   study;
  199.                   print ".IX foo\n" if /\bfoo\b/;
  200.                   print ".IX bar\n" if /\bbar\b/;
  201.                   print ".IX blurfl\n" if /\bblurfl\b/;
  202.                   ...
  203.                   print;
  204.           }
  205.  
  206.      In searching for `/\bfoo\b/', only those locations in `$_' that
  207.      contain `f' will be looked at, because `f' is rarer than `o'.  In
  208.      general, this is a big win except in pathological cases.  The only
  209.      question is whether it saves you more time than it took to build
  210.      the linked list in the first place.
  211.  
  212.      Note that if you have to look for strings that you don't know till
  213.      runtime, you can build an entire loop as a string and eval that to
  214.      avoid recompiling all your patterns all the time.  Together with
  215.      undefining `$/' to input entire files as one record, this can be
  216.      very fast, often faster than specialized programs like `fgrep'.
  217.      The following scans a list of files (`@files') for a list of words
  218.      (`@words'), and prints out the names of those files that contain a
  219.      match:
  220.  
  221.           $search = 'while (<>) { study;';
  222.           foreach $word (@words) {
  223.               $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
  224.           }
  225.           $search .= "}";
  226.           @ARGV = @files;
  227.           undef $/
  228.           eval $search;           # this screams
  229.           $/ = "\n";              # put back to normal input delim
  230.           foreach $file (sort keys(%seen)) {
  231.               print $file, "\n";
  232.           }
  233.  
  234. tr/SEARCHLIST/REPLACEMENTLIST/cds
  235. y/SEARCHLIST/REPLACEMENTLIST/cds
  236.      Translates all occurrences of the characters found in the search
  237.      list with the corresponding character in the replacement list.  It
  238.      returns the number of characters replaced or deleted.  If no
  239.      string is specified via the `=~' or `!~' operator, the `$_' string
  240.      is translated.  (The string specified with `=~' must be a scalar
  241.      variable, an array element, or an assignment to one of those, i.e.
  242.      an lvalue.)  For `sed' devotees, `y' is provided as a synonym for
  243.      `tr'.  If the SEARCHLIST is delimited by bracketing quotes, the
  244.      REPLACEMENTLIST has its own pair of quotes, which may or may not
  245.      be bracketing quotes, e.g. `tr[A-Z][a-z]' or `tr(+-*/)/ABCD/'.
  246.  
  247.      If the `c' modifier is specified, the SEARCHLIST character set is
  248.      complemented.  If the `d' modifier is specified, any characters
  249.      specified by SEARCHLIST that are not found in REPLACEMENTLIST are
  250.      deleted.  (Note that this is slightly more flexible than the
  251.      behavior of some `tr' programs, which delete anything they find in
  252.      the SEARCHLIST, period.)  If the `s' modifier is specified,
  253.      sequences of characters that were translated to the same character
  254.      are squashed down to 1 instance of the character.
  255.  
  256.      If the `d' modifier was used, the REPLACEMENTLIST is always
  257.      interpreted exactly as specified.  Otherwise, if the
  258.      REPLACEMENTLIST is shorter than the SEARCHLIST, the final
  259.      character is replicated till it is long enough.  If the
  260.      REPLACEMENTLIST is null, the SEARCHLIST is replicated.  The latter
  261.      is useful for counting characters in a class, or for squashing
  262.      character sequences in a class.
  263.  
  264.      Examples:
  265.  
  266.           $ARGV[1] =~ y/A-Z/a-z/;          # canonicalize to lower case
  267.           
  268.           $cnt = tr/*/*/;                  # count the stars in $_
  269.           
  270.           $cnt = tr/0-9//;                 # count the digits in $_
  271.           
  272.           tr/a-zA-Z//s;                    # bookkeeper -> bokeper
  273.           
  274.           ($HOST = $host) =~ tr/a-z/A-Z/;
  275.           
  276.           y/\001-@[-_{-\177/ /;            # change non-alphas to space
  277.                                            #   (before the c & s modifiers)
  278.           y/a-zA-Z/ /cs;                   # change non-alphas to single space
  279.                                            #   (version 3.0 patchlevel 40+)
  280.           
  281.           tr/\200-\377/\0-\177/;           # delete 8th bit
  282.  
  283. 
  284. File: perl.info,  Node: System Interaction,  Next: Networking Functions,  Prev: Search and Replace Functions,  Up: Commands
  285.  
  286. System Interaction
  287. ==================
  288.  
  289. alarm(SECONDS)
  290. alarm SECONDS
  291.      Arranges to have a `SIGALRM' delivered to this process after the
  292.      specified number of seconds (minus 1, actually) have elapsed.
  293.      Thus, `alarm(15)' will cause a `SIGALRM' at some point more than 14
  294.      seconds in the future.  Only one timer may be counting at once.
  295.      Each call disables the previous timer, and an argument of 0 may be
  296.      supplied to cancel the previous timer without starting a new one.
  297.      The returned value is the amount of time remaining on the previous
  298.      timer.
  299.  
  300. chroot(FILENAME)
  301. chroot FILENAME
  302. chroot
  303.      Does the same as the system call of that name.  If you don't know
  304.      what it does, don't worry about it.  If FILENAME is omitted, does
  305.      `chroot' to `$_'.
  306.  
  307. die(LIST)
  308. die LIST
  309. die
  310.      Outside of an `eval', prints the value of LIST to `STDERR' and
  311.      exits with the current value of `$!' (errno).  As of version 3.0
  312.      patchlevel 27, `die' without LIST specified is equivalent to
  313.           die 'Died';
  314.      If `$!' is 0, exits with the value of `($? >> 8)' (`command`
  315.      status).  If `($? >> 8)' is 0, exits with 255.  Inside an `eval',
  316.      the error message is stuffed into `$@' and the `eval' is
  317.      terminated with the undefined value.
  318.  
  319.      Equivalent examples:
  320.  
  321.           die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
  322.           
  323.           chdir '/usr/spool/news' || die "Can't cd to spool: $!\n"
  324.  
  325.      If the value of EXPR does not end in a newline, the current script
  326.      line number and input line number (if any) are also printed, and a
  327.      newline is supplied.  Hint: sometimes appending ", stopped" to your
  328.      message will cause it to make better sense when the string "at foo
  329.      line 123" is appended.  Suppose you are running script "canasta".
  330.  
  331.           die "/etc/games is no good";
  332.           die "/etc/games is no good, stopped";
  333.  
  334.      produce, respectively
  335.  
  336.           /etc/games is no good at canasta line 123.
  337.           /etc/games is no good, stopped at canasta line 123.
  338.  
  339.      See also `exit'.
  340.  
  341. exec(LIST)
  342. exec LIST
  343.      If there is more than one argument in LIST, or if LIST is an array
  344.      with more than one value, calls `execvp()' with the arguments in
  345.      LIST.  If there is only one scalar argument, the argument is
  346.      checked for shell metacharacters.  If there are any, the entire
  347.      argument is passed to `/bin/sh -c' for parsing.  If there are
  348.      none, the argument is split into words and passed directly to
  349.      `execvp()', which is more efficient.  Note: `exec' (and `system')
  350.      do not flush your output buffer, so you may need to set `$|' to
  351.      avoid lost output.  Examples:
  352.  
  353.           exec '/bin/echo', 'Your arguments are: ', @ARGV;
  354.           exec "sort $outfile | uniq";
  355.  
  356.      If you don't really want to execute the first argument, but want
  357.      to lie to the program you are executing about its own name, you
  358.      can specify the program you actually want to run by assigning that
  359.      to a variable and putting the name of the variable in front of the
  360.      LIST without a comma.  (This always forces interpretation of the
  361.      LIST as a multi-valued list, even if there is only a single scalar
  362.      in the list.) Example:
  363.  
  364.           $shell = '/bin/csh';
  365.           exec $shell '-sh';              # pretend it's a login shell
  366.  
  367. exit(EXPR)
  368. exit EXPR
  369.      Evaluates EXPR and exits immediately with that value.  Example:
  370.  
  371.           $ans = <STDIN>;
  372.           exit 0 if $ans =~ /^[Xx]/;
  373.  
  374.      See also `die'.  If EXPR is omitted, exits with 0 status.
  375.  
  376. fork
  377.      Does a `fork()' call.  Returns the child pid to the parent process
  378.      and 0 to the child process.  Note: unflushed buffers remain
  379.      unflushed in both processes, which means you may need to set `$|'
  380.      to avoid duplicate output.
  381.  
  382. getpwnam(NAME)
  383. getgrnam(NAME)
  384. gethostbyname(NAME)
  385. getnetbyname(NAME)
  386. getprotobyname(NAME)
  387. getpwuid(UID)
  388. getgrgid(GID)
  389. getservbyname(NAME,PROTO)
  390. gethostbyaddr(ADDR,ADDRTYPE)
  391. getnetbyaddr(ADDR,ADDRTYPE)
  392. getprotobynumber(NUMBER)
  393. getservbyport(PORT,PROTO)
  394. getpwent
  395. getgrent
  396. gethostent
  397. getnetent
  398. getprotoent
  399. getservent
  400. setpwent
  401. setgrent
  402. sethostent(STAYOPEN)
  403. setnetent(STAYOPEN)
  404. setprotoent(STAYOPEN)
  405. setservent(STAYOPEN)
  406. endpwent
  407. endgrent
  408. endhostent
  409. endnetent
  410. endprotoent
  411. endservent
  412.      These routines perform the same functions as their counterparts in
  413.      the system library.  With an array context, the return values from
  414.      the various get routines are as follows:
  415.  
  416.           ($name,$passwd,$uid,$gid,
  417.              $quota,$comment,$gcos,$dir,$shell) = getpw...
  418.           ($name,$passwd,$gid,$members) = getgr...
  419.           ($name,$aliases,$addrtype,$length,@addrs) = gethost...
  420.           ($name,$aliases,$addrtype,$net) = getnet...
  421.           ($name,$aliases,$proto) = getproto...
  422.           ($name,$aliases,$port,$proto) = getserv...
  423.  
  424.      (If the entry doesn't exist you get a null list.)
  425.  
  426.      Within a scalar context, you get the name, unless the function was
  427.      a lookup by name, in which case you get the other thing, whatever
  428.      it is.  (If the entry doesn't exist you get the undefined value.)
  429.      For example:
  430.  
  431.           $uid = getpwnam
  432.           $name = getpwuid
  433.           $name = getpwent
  434.           $gid = getgrnam
  435.           $name = getgrgid
  436.           $name = getgrent
  437.           etc.
  438.  
  439.      The `$members' value returned by `getgr...' is a space separated
  440.      list of the login names of the members of the group.
  441.  
  442.      For the `gethost...' functions, if the `h_errno' variable is
  443.      supported in C, it will be returned to you via `$?' if the function
  444.      call fails.  The `@addrs' value returned by a successful call is a
  445.      list of the raw addresses returned by the corresponding system
  446.      library call.  In the Internet domain, each address is four bytes
  447.      long and you can unpack it by saying something like:
  448.  
  449.           ($a,$b,$c,$d) = unpack('C4',$addr[0]);
  450.  
  451. getlogin
  452.      Returns the current login from `/etc/utmp', if any.  If null, use
  453.      `getpwuid'.
  454.  
  455.           $login = getlogin || (getpwuid($<))[0] || "Somebody";
  456.  
  457. getpgrp(PID)
  458. getpgrp PID
  459. getpgrp
  460.      Returns the current process group for the specified PID, 0 for the
  461.      current process.  Will produce a fatal error if used on a machine
  462.      that doesn't implement `getpgrp(2)'.  If PID is omitted, returns
  463.      process group of current process.  PID can be an expression.
  464.  
  465. getppid
  466.      Returns the process id of the parent process.
  467.  
  468. getpriority(WHICH,WHO)
  469.      Returns the current priority for a process, a process group, or a
  470.      user.  (See the `getpriority(2)' man page.)  Will produce a fatal
  471.      error if used on a machine that doesn't implement `getpriority(2)'.
  472.  
  473. ioctl(FILEHANDLE,FUNCTION,SCALAR)
  474.      Implements the `ioctl(2)' function.  You'll probably have to say
  475.  
  476.           require "ioctl.ph";   # probably `/usr/local/lib/perl/ioctl.ph'
  477.  
  478.      first to get the correct function definitions.  If `ioctl.ph'
  479.      doesn't exist or doesn't have the correct definitions you'll have
  480.      to roll your own, based on your C header files such as
  481.      `<sys/ioctl.h>'.  (There is a perl script called `h2ph' that comes
  482.      with the perl kit which may help you in this.)  SCALAR will be
  483.      read and/or written depending on the FUNCTION--a pointer to the
  484.      string value of SCALAR will be passed as the third argument of the
  485.      actual `ioctl' call.  (If SCALAR has no string value but does have
  486.      a numeric value, that value will be passed rather than a pointer
  487.      to the string value.  To guarantee this to be true, add a 0 to the
  488.      scalar before using it.)  The `pack()' and `unpack()' functions
  489.      are useful for manipulating the values of structures used by
  490.      `ioctl()'.
  491.  
  492.      The following example sets the erase character to DEL.
  493.  
  494.           require 'ioctl.ph';
  495.           $sgttyb_t = "ccccs";            # 4 chars and a short
  496.           if (ioctl(STDIN,$TIOCGETP,$sgttyb)) {
  497.                   @ary = unpack($sgttyb_t,$sgttyb);
  498.                   $ary[2] = 127;
  499.                   $sgttyb = pack($sgttyb_t,@ary);
  500.                   ioctl(STDIN,$TIOCSETP,$sgttyb)
  501.                           || die "Can't ioctl: $!";
  502.           }
  503.  
  504.      The return value of `ioctl' (and `fcntl') is as follows:
  505.  
  506.           if OS returns:                  perl returns:
  507.             -1                              undefined value
  508.             0                               string "0 but true"
  509.             anything else                   that number
  510.  
  511.      Thus perl returns true on success and false on failure, yet you
  512.      can still easily determine the actual value returned by the
  513.      operating system:
  514.  
  515.           ($retval = ioctl(...)) || ($retval = -1);
  516.           printf "System returned %d\n", $retval;
  517.  
  518. kill(LIST)
  519. kill LIST
  520.      Sends a signal to a list of processes.  The first element of the
  521.      list must be the signal to send.  Returns the number of processes
  522.      successfully signaled.
  523.  
  524.           $cnt = kill 1, $child1, $child2;
  525.           kill 9, @goners;
  526.  
  527.      If the signal is negative, kills process groups instead of
  528.      processes.  (On System V, a negative *process* number will also
  529.      kill process groups, but that's not portable.)  You may use a
  530.      signal name in quotes.
  531.  
  532. setpgrp(PID,PGRP)
  533.      Sets the current process group for the specified PID, 0 for the
  534.      current process.  Will produce a fatal error if used on a machine
  535.      that doesn't implement `setpgrp(2)'.
  536.  
  537. setpriority(WHICH,WHO,PRIORITY)
  538.      Sets the current priority for a process, a process group, or a
  539.      user.  (See the `setpriority(2)' man page.)  Will produce a fatal
  540.      error if used on a machine that doesn't implement `setpriority(2)'.
  541.  
  542. sleep(EXPR)
  543. sleep EXPR
  544. sleep
  545.      Causes the script to sleep for EXPR seconds, or forever if no
  546.      EXPR.  May be interrupted by sending the process a `SIGALRM'.
  547.      Returns the number of seconds actually slept.  You probably cannot
  548.      mix `alarm()' and `sleep()' calls, since `sleep()' is often
  549.      implemented using `alarm()'.
  550.  
  551. syscall(LIST)
  552. syscall LIST
  553.      Calls the system call specified as the first element of the list,
  554.      passing the remaining elements as arguments to the system call.  If
  555.      unimplemented, produces a fatal error.  The arguments are
  556.      interpreted as follows: if a given argument is numeric, the
  557.      argument is passed as an int.  If not, the pointer to the string
  558.      value is passed.  You are responsible to make sure a string is
  559.      pre-extended long enough to receive any result that might be
  560.      written into a string.  If your integer arguments are not literals
  561.      and have never been interpreted in a numeric context, you may need
  562.      to add 0 to them to force them to look like numbers.
  563.  
  564.           require 'syscall.ph';         # may need to run h2ph
  565.           syscall(&SYS_write, fileno(STDOUT), "hi there\n", 9);
  566.  
  567. sysread(FILEHANDLE,SCALAR,LENGTH,OFFSET)
  568. sysread(FILEHANDLE,SCALAR,LENGTH)
  569.      Attempts to read LENGTH bytes of data into variable SCALAR from
  570.      the specified FILEHANDLE, using the system call `read(2)'.  It
  571.      bypasses stdio, so mixing this with other kinds of reads may cause
  572.      confusion.  Returns the number of bytes actually read, or `undef'
  573.      if there was an error.  SCALAR will be grown or shrunk to the
  574.      length actually read.  An OFFSET may be specified to place the
  575.      read data at some other place than the beginning of the string.
  576.  
  577. syswrite(FILEHANDLE,SCALAR,LENGTH,OFFSET)
  578. syswrite(FILEHANDLE,SCALAR,LENGTH)
  579.      Attempts to write LENGTH bytes of data from variable SCALAR to the
  580.      specified FILEHANDLE, using the system call `write(2)'.  It
  581.      bypasses stdio, so mixing this with prints may cause confusion.
  582.      Returns the number of bytes actually written, or `undef' if there
  583.      was an error.  An OFFSET may be specified to place the read data
  584.      at some other place than the beginning of the string.
  585.  
  586. system(LIST)
  587. system LIST
  588.      Does exactly the same thing as `exec LIST' except that a fork is
  589.      done first, and the parent process waits for the child process to
  590.      complete.  Note that argument processing varies depending on the
  591.      number of arguments.  The return value is the exit status of the
  592.      program as returned by the `wait()' call.  To get the actual exit
  593.      value divide by 256.  See also `exec'.
  594.  
  595. times
  596.      Returns a four-element array giving the user and system times, in
  597.      seconds, for this process and the children of this process.
  598.  
  599.           ($user,$system,$cuser,$csystem) = times;
  600.  
  601. umask(EXPR)
  602. umask EXPR
  603. umask
  604.      Sets the umask for the process and returns the old one.  If EXPR
  605.      is omitted, merely returns current umask.
  606.  
  607. wait
  608.      Waits for a child process to terminate and returns the pid of the
  609.      deceased process, or -1 if there are no child processes.  The
  610.      status is returned in `$?'.
  611.  
  612. waitpid(PID,FLAGS)
  613.      Waits for a particular child process to terminate and returns the
  614.      pid of the deceased process or -1 if there are no such child
  615.      process.  The status is returns in `$?'.  If you say
  616.  
  617.           require "sys/wait.ph";
  618.           ...
  619.           waitpid(-1,&WNOHANG);
  620.  
  621.      then you can do a non-blocking wait for any process.  Non-blocking
  622.      wait is only available on machines supporting either the
  623.      `waitpid(2)' or `wait4(2)' system calls.  However, waiting for a
  624.      particular pid with FLAGS of 0 is implemented everywhere.  (*Perl*
  625.      emulates the system call by remembering the status values of
  626.      processes that have exited but have not been harvested by the
  627.      *Perl* script yet.)
  628.  
  629. warn(LIST)
  630. warn LIST
  631.      Produces a message on `STDERR' just like `die', but doesn't exit.
  632.  
  633. 
  634. File: perl.info,  Node: Networking Functions,  Next: System V IPC,  Prev: System Interaction,  Up: Commands
  635.  
  636. Networking Functions - Interprocess Communication
  637. =================================================
  638.  
  639. accept(NEWSOCKET,GENERICSOCKET)
  640.      Does the same thing that the `accept' system call does.  Returns
  641.      true if it succeeded, false otherwise.  *Note Interprocess
  642.      Communication::, for an example.
  643.  
  644. bind(SOCKET,NAME)
  645.      Does the same thing that the `bind' system call does.  Returns true
  646.      if it succeeded, false otherwise.  NAME should be a packed address
  647.      of the proper type for the socket.  *Note Interprocess
  648.      Communication::, for an example.
  649.  
  650. connect(SOCKET,NAME)
  651.      Does the same thing that the `connect' system call does.  Returns
  652.      true if it succeeded, false otherwise.  NAME should be a packed
  653.      address of the proper type for the socket.  *Note Interprocess
  654.      Communication::, for an example.
  655.  
  656. getpeername(SOCKET)
  657.      Returns the packed *sockaddr* address of other end of the SOCKET
  658.      connection.
  659.  
  660.           # An internet sockaddr
  661.           $sockaddr = 'S n a4 x8';
  662.           $hersockaddr = getpeername(S);
  663.           ($family, $port, $heraddr) = unpack($sockaddr,$hersockaddr);
  664.  
  665. getsockname(SOCKET)
  666.      Returns the packed *sockaddr* address of this end of the SOCKET
  667.      connection.
  668.  
  669.           # An internet sockaddr
  670.           $sockaddr = 'S n a4 x8';
  671.           $mysockaddr = getsockname(S);
  672.           ($family, $port, $myaddr) = unpack($sockaddr,$mysockaddr);
  673.  
  674. getsockopt(SOCKET,LEVEL,OPTNAME)
  675.      Returns the socket option requested, or undefined if there is an
  676.      error.
  677.  
  678. listen(SOCKET,QUEUESIZE)
  679.      Does the same thing that the `listen' system call does.  Returns
  680.      true if it succeeded, false otherwise.  *Note Interprocess
  681.      Communication::, for an example.
  682.  
  683. recv(SOCKET,SCALAR,LEN,FLAGS)
  684.      Receives a message on a socket.  Attempts to receive LENGTH bytes
  685.      of data into variable SCALAR from the specified SOCKET filehandle.
  686.      Returns the address of the sender, or the undefined value if
  687.      there's an error.  SCALAR will be grown or shrunk to the length
  688.      actually read.  Takes the same flags as the system call of the same
  689.      name.
  690.  
  691. send(SOCKET,MSG,FLAGS,TO)
  692. send(SOCKET,MSG,FLAGS)
  693.      Sends a message on a socket.  Takes the same flags as the system
  694.      call of the same name.  On unconnected sockets you must specify a
  695.      destination to send TO.  Returns the number of characters sent, or
  696.      the undefined value if there is an error.
  697.  
  698. setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
  699.      Sets the socket option requested.  Returns undefined if there is an
  700.      error.  OPTVAL may be specified as `undef' if you don't want to
  701.      pass an argument.
  702.  
  703. shutdown(SOCKET,HOW)
  704.      Shuts down a socket connection in the manner indicated by HOW,
  705.      which has the same interpretation as in the system call of the same
  706.      name.
  707.  
  708. socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
  709.      Opens a socket of the specified kind and attaches it to filehandle
  710.      SOCKET.  DOMAIN, TYPE and PROTOCOL are specified the same as for
  711.      the system call of the same name.  You may need to run `h2ph' on
  712.      `sys/socket.h' to get the proper values handy in a perl library
  713.      file.  Return true if successful.  *Note Interprocess
  714.      Communication::, for an example.
  715.  
  716. socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
  717.      Creates an unnamed pair of sockets in the specified domain, of the
  718.      specified type.  DOMAIN, TYPE and PROTOCOL are specified the same
  719.      as for the system call of the same name.  If unimplemented, yields
  720.      a fatal error.  Return true if successful.
  721.  
  722. 
  723. File: perl.info,  Node: System V IPC,  Next: Time Functions,  Prev: Networking Functions,  Up: Commands
  724.  
  725. Networking Functions - System V IPC
  726. ===================================
  727.  
  728. msgctl(ID,CMD,ARG)
  729.      Calls the System V IPC function `msgctl'.  If CMD is &IPC_STAT,
  730.      then ARG must be a variable which will hold the returned msqid_ds
  731.      structure.  Returns like `ioctl': the undefined value for error,
  732.      "0 but true" for zero, or the actual return value otherwise.
  733.  
  734. msgget(KEY,FLAGS)
  735.      Calls the System V IPC function `msgget'.  Returns the message
  736.      queue id, or the undefined value if there is an error.
  737.  
  738. msgsnd(ID,MSG,FLAGS)
  739.      Calls the System V IPC function `msgsnd' to send the message MSG
  740.      to the message queue ID.  MSG must begin with the long integer
  741.      message type, which may be created with `pack("L", $type)'.
  742.      Returns true if successful, or false if there is an error.
  743.  
  744. msgrcv(ID,VAR,SIZE,TYPE,FLAGS)
  745.      Calls the System V IPC function `msgrcv' to receive a message from
  746.      message queue ID into variable VAR with a maximum message size of
  747.      SIZE.  Note that if a message is received, the message type will
  748.      be the first thing in VAR, and the maximum length of VAR is SIZE
  749.      plus the size of the message type.  Returns true if successful, or
  750.      false if there is an error.
  751.  
  752. semctl(ID,SEMNUM,CMD,ARG)
  753.      Calls the System V IPC function `semctl'.  If CMD is &IPC_STAT or
  754.      &GETALL, then ARG must be a variable which will hold the returned
  755.      semid_ds structure or semaphore value array.  Returns like
  756.      `ioctl': the undefined value for error, "0 but true" for zero, or
  757.      the actual return value otherwise.
  758.  
  759. semget(KEY,NSEMS,SIZE,FLAGS)
  760.      Calls the System V IPC function `semget'.  Returns the semaphore
  761.      id, or the undefined value if there is an error.
  762.  
  763. semop(KEY,OPSTRING)
  764.      Calls the System V IPC function `semop' to perform semaphore
  765.      operations such as signaling and waiting.  OPSTRING must be a
  766.      packed array of semop structures.  Each semop structure can be
  767.      generated with `pack("sss", $semnum, $semop, $semflag)'.  The
  768.      number of semaphore operations is implied by the length of
  769.      OPSTRING.  Returns true if successful, or false if there is an
  770.      error.  As an example, the following code waits on semaphore
  771.      $semnum of semaphore id $semid:
  772.  
  773.           $semop = pack("sss", $semnum, -1, 0);
  774.           die "Semaphore trouble: $!\n" unless semop($semid, $semop);
  775.  
  776.      To signal the semaphore, replace `-1' with `1'.
  777.  
  778. shmctl(ID,CMD,ARG)
  779.      Calls the System V IPC function `shmctl'.  If CMD is &IPC_STAT,
  780.      then ARG must be a variable which will hold the returned shmid_ds
  781.      structure.  Returns like `ioctl': the undefined value for error,
  782.      "0 but true" for zero, or the actual return value otherwise.
  783.  
  784. shmget(KEY,SIZE,FLAGS)
  785.      Calls the System V IPC function `shmget'.  Returns the shared
  786.      memory segment id, or the undefined value if there is an error.
  787.  
  788. shmread(ID,VAR,POS,SIZE)
  789. shmwrite(ID,STRING,POS,SIZE)
  790.      Reads or writes the System V shared memory segment ID starting at
  791.      position POS for size SIZE by attaching to it, copying in/out, and
  792.      detaching from it.  When reading, VAR must be a variable which
  793.      will hold the data read.  When writing, if STRING is too long,
  794.      only SIZE bytes are used; if STRING is too short, nulls are
  795.      written to fill out SIZE bytes.  Returns true if successful, or
  796.      false if there is an error.
  797.  
  798. 
  799. File: perl.info,  Node: Time Functions,  Next: DBM Functions,  Prev: System V IPC,  Up: Commands
  800.  
  801. Time Related Functions
  802. ======================
  803.  
  804. gmtime(EXPR)
  805. gmtime EXPR
  806. gmtime
  807.      Converts a time as returned by the `time' function to a 9-element
  808.      array with the time analyzed for the Greenwich timezone.
  809.      Typically used as follows:
  810.  
  811.           ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
  812.                                                       = gmtime(time);
  813.  
  814.      All array elements are numeric, and come straight out of a `struct
  815.      tm'.  In particular this means that `$mon' has the range `0..11'
  816.      and `$wday' has the range `0..6'.  If EXPR is omitted, does
  817.      `gmtime(time)'.
  818.  
  819. localtime(EXPR)
  820. localtime EXPR
  821. localtime
  822.      Converts a time as returned by the time function to a 9-element
  823.      array with the time analyzed for the local timezone.  Typically
  824.      used as follows:
  825.  
  826.           ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
  827.                                                   = localtime(time);
  828.  
  829.      All array elements are numeric, and come straight out of a `struct
  830.      tm'.  In particular this means that $mon has the range `0..11' and
  831.      $wday has the range `0..6'.  If EXPR is omitted, does
  832.      `localtime(time)'.
  833.  
  834. time
  835.      Returns the number of non-leap seconds since 00:00:00 UTC, January
  836.      1, 1970.  Suitable for feeding to `gmtime()' and `localtime()'.
  837.  
  838. 
  839. File: perl.info,  Node: DBM Functions,  Next: Flow Control Functions,  Prev: Time Functions,  Up: Commands
  840.  
  841. DBM Functions
  842. =============
  843.  
  844. dbmclose(ASSOC_ARRAY)
  845. dbmclose ASSOC_ARRAY
  846.      Breaks the binding between a dbm file and an associative array.
  847.      The values remaining in the associative array are meaningless
  848.      unless you happen to want to know what was in the cache for the
  849.      dbm file.  This function is only useful if you have ndbm.
  850.  
  851. dbmopen(ASSOC,DBNAME,MODE)
  852.      This binds a dbm or ndbm file to an associative array.  ASSOC is
  853.      the name of the associative array.  (Unlike normal open, the first
  854.      argument is *NOT* a filehandle, even though it looks like one).
  855.      DBNAME is the name of the database (without the `.dir' or `.pag'
  856.      extension).  If the database does not exist, it is created with
  857.      protection specified by MODE (as modified by the umask).  If your
  858.      system only supports the older dbm functions, you may perform only
  859.      one `dbmopen' in your program.  If your system has neither dbm nor
  860.      ndbm, calling `dbmopen' produces a fatal error.
  861.  
  862.      Values assigned to the associative array prior to the `dbmopen' are
  863.      lost.  A certain number of values from the dbm file are cached in
  864.      memory.  By default this number is 64, but you can increase it by
  865.      preallocating that number of garbage entries in the associative
  866.      array before the `dbmopen'.  You can flush the cache if necessary
  867.      with the reset command.
  868.  
  869.      If you don't have write access to the dbm file, you can only read
  870.      associative array variables, not set them.  If you want to test
  871.      whether you can write, either use file tests or try setting a
  872.      dummy array entry inside an eval, which will trap the error.
  873.  
  874.      Note that functions such as `keys()' and `values()' may return
  875.      huge array values when used on large dbm files.  You may prefer to
  876.      use the `each()' function to iterate over large dbm files.
  877.      Example:
  878.  
  879.           # print out history file offsets
  880.           dbmopen(HIST,'/usr/lib/news/history',0666);
  881.           while (($key,$val) = each %HIST) {
  882.                   print $key, ' = ', unpack('L',$val), "\n";
  883.           }
  884.           dbmclose(HIST);
  885.  
  886. 
  887. File: perl.info,  Node: Flow Control Functions,  Next: Perl Library Functions,  Prev: DBM Functions,  Up: Commands
  888.  
  889. Flow Control Functions
  890. ======================
  891.  
  892. do BLOCK
  893.      Returns the value of the last command in the sequence of commands
  894.      indicated by BLOCK.  When modified by a loop modifier, executes
  895.      the BLOCK once before testing the loop condition.  (On other
  896.      statements the loop modifiers test the conditional first.)
  897.  
  898. goto LABEL
  899.      Finds the statement labeled with LABEL and resumes execution
  900.      there.  Currently you may only go to statements in the main body
  901.      of the program that are not nested inside a `do {}' construct.
  902.      This statement is not implemented very efficiently, and is here
  903.      only to make the *sed*-to-*perl* translator easier.  I may change
  904.      its semantics at any time, consistent with support for translated
  905.      `sed' scripts.  Use it at your own risk.  Better yet, don't use it
  906.      at all.
  907.  
  908. last LABEL
  909. last
  910.      The `last' command is like the `break' statement in C (as used in
  911.      loops); it immediately exits the loop in question.  If the LABEL
  912.      is omitted, the command refers to the innermost enclosing loop.
  913.      The `continue' block, if any, is not executed:
  914.  
  915.           line: while (<STDIN>) {
  916.                   last line if /^$/;      # exit when done with header
  917.                   ...
  918.           }
  919.  
  920. next LABEL
  921. next
  922.      The `next' command is like the `continue' statement in C; it
  923.      starts the next iteration of the loop:
  924.  
  925.           line: while (<STDIN>) {
  926.                   next line if /^#/;      # discard comments
  927.                   ...
  928.           }
  929.  
  930.      Note that if there were a `continue' block on the above, it would
  931.      get executed even on discarded lines.  If the LABEL is omitted,
  932.      the command refers to the innermost enclosing loop.
  933.  
  934. redo LABEL
  935. redo
  936.      The `redo' command restarts the loop block without evaluating the
  937.      conditional again.  The `continue' block, if any, is not executed.
  938.      If the LABEL is omitted, the command refers to the innermost
  939.      enclosing loop.  This command is normally used by programs that
  940.      want to lie to themselves about what was just input:
  941.  
  942.           # a simpleminded Pascal comment stripper
  943.           # (warning: assumes no { or } in strings)
  944.           line: while (<STDIN>) {
  945.                   while (s|({.*}.*){.*}|$1 |) {}
  946.                   s|{.*}| |;
  947.                   if (s|{.*| |) {
  948.                           $front = $_;
  949.                           while (<STDIN>) {
  950.                                   if (/}/) {    # end of comment?
  951.                                           s|^|$front{|;
  952.                                           redo line;
  953.                                   }
  954.                           }
  955.                   }
  956.                   print;
  957.           }
  958.  
  959. 
  960. File: perl.info,  Node: Perl Library Functions,  Next: Subroutine Functions,  Prev: Flow Control Functions,  Up: Commands
  961.  
  962. Perl Library Functions
  963. ======================
  964.  
  965. require(EXPR)
  966. require EXPR
  967. require
  968.      Includes the library file specified by EXPR, or by `$_' if EXPR is
  969.      not supplied.  Has semantics similar to the following subroutine:
  970.  
  971.           sub require {
  972.               local($filename) = @_;
  973.               return 1 if $INC{$filename};
  974.               local($realfilename,$result);
  975.               ITER: {
  976.                   foreach $prefix (@INC) {
  977.                       $realfilename = "$prefix/$filename";
  978.                       if (-f $realfilename) {
  979.                           $result = do $realfilename;
  980.                           last ITER;
  981.                       }
  982.                   }
  983.                   die "Can't find $filename in \@INC";
  984.               }
  985.               die $@ if $@;
  986.               die "$filename did not return true value" unless $result;
  987.               $INC{$filename} = $realfilename;
  988.               $result;
  989.           }
  990.  
  991.      Note that the file will not be included twice under the same
  992.      specified name.  The file must return true as the last statement
  993.      to indicate successful execution of any initialization code, so
  994.      it's customary to end such a file with `1;' unless you're sure
  995.      it'll return true otherwise.
  996.  
  997. do EXPR
  998.      Uses the value of EXPR as a filename and executes the contents of
  999.      the file as a *perl* script.  Its primary use is to include
  1000.      subroutines from a *perl* subroutine library.
  1001.  
  1002.           do 'stat.pl';
  1003.  
  1004.      is just like
  1005.  
  1006.           eval `cat stat.pl`;
  1007.  
  1008.      except that it's more efficient, more concise, keeps track of the
  1009.      current filename for error messages, and searches all the `-I'
  1010.      libraries if the file isn't in the current directory (*note "INC"
  1011.      array: Predefined Names., for more info).  It's the same, however,
  1012.      in that it does reparse the file every time you call it, so if you
  1013.      are going to use the file inside a loop you might prefer to use
  1014.      `-P' and `#include', at the expense of a little more startup time.
  1015.      (The main problem with `#include' is that cpp doesn't grok `#'
  1016.      comments--a workaround is to use `;#' for standalone comments.)
  1017.      Note that the following are *NOT* equivalent:
  1018.  
  1019.           do $foo;        # eval a file
  1020.           do $foo();      # call a subroutine
  1021.  
  1022.      Note that inclusion of library routines is better done with the
  1023.      `require' operator.
  1024.  
  1025. 
  1026. File: perl.info,  Node: Subroutine Functions,  Next: Variable Functions,  Prev: Perl Library Functions,  Up: Commands
  1027.  
  1028. Subroutine Functions
  1029. ====================
  1030.  
  1031. caller(EXPR)
  1032. caller
  1033.      Returns the context of the current subroutine call:
  1034.  
  1035.           ($package,$filename,$line) = caller;
  1036.  
  1037.      With EXPR, returns some extra information that the debugger uses
  1038.      to print a stack trace.  The value of EXPR indicates how many call
  1039.      frames to go back before the current one.
  1040.  
  1041. do SUBROUTINE (LIST)
  1042.      Executes a SUBROUTINE declared by a `sub' declaration, and returns
  1043.      the value of the last expression evaluated in SUBROUTINE.  If
  1044.      there is no subroutine by that name, produces a fatal error.  (You
  1045.      may use the `defined' operator to determine if a subroutine
  1046.      exists.)  If you pass arrays as part of LIST you may wish to pass
  1047.      the length of the array in front of each array.  (*Note
  1048.      Subroutines::.) The parentheses are required to avoid confusion
  1049.      with the `do EXPR' form.
  1050.  
  1051.      SUBROUTINE may also be a single scalar variable, in which case the
  1052.      name of the subroutine to execute is take from the variable.
  1053.  
  1054.      As an alternate (and preferred) form, you may call a subroutine by
  1055.      prefixing the name with an ampersand: `&foo(@args)'.  If you
  1056.      aren't passing any arguments, you don't have to use parentheses.
  1057.      If you omit the parentheses, no `@_' array is passed to the
  1058.      subroutine.  The `&' form is also used to specify subroutines to
  1059.      the `defined' and `undef' operators.
  1060.  
  1061.           if (defined &$var) { &$var($parm); undef &$var; }
  1062.  
  1063. local(LIST)
  1064.      Declares the listed variables to be local to the enclosing block,
  1065.      subroutine, `eval' or `do'.  All the listed elements must be legal
  1066.      lvalues.  This operator works by saving the current values of
  1067.      those variables in LIST on a hidden stack and restoring them upon
  1068.      exiting the block, subroutine or `eval'.  This means that called
  1069.      subroutines can also reference the local variable, but not the
  1070.      global one.  The LIST may be assigned to if desired, which allows
  1071.      you to initialize your local variables.  (If no initializer is
  1072.      given for a particular variable, it is created with an undefined
  1073.      value.)  Commonly this is used to name the parameters to a
  1074.      subroutine.  Examples:
  1075.  
  1076.           sub RANGEVAL {
  1077.                   local($min, $max, $thunk) = @_;
  1078.                   local($result) = '';
  1079.                   local($i);
  1080.           
  1081.                   # Presumably $thunk makes reference to $i
  1082.           
  1083.                   for ($i = $min; $i < $max; $i++) {
  1084.                           $result .= eval $thunk;
  1085.                   }
  1086.           
  1087.                   $result;
  1088.           }
  1089.           
  1090.           if ($sw eq '-v') {
  1091.               # init local array with global array
  1092.               local(@ARGV) = @ARGV;
  1093.               unshift(@ARGV,'echo');
  1094.               system @ARGV;
  1095.           }
  1096.           # @ARGV restored
  1097.           
  1098.           # temporarily add to digits associative array
  1099.           if ($base12) {
  1100.                   # (NOTE: not claiming this is efficient!)
  1101.                   local(%digits) = (%digits,'t',10,'e',11);
  1102.                   do parse_num();
  1103.           }
  1104.  
  1105.      Note that `local()' is a run-time command, and so gets executed
  1106.      every time through a loop, using up more stack storage each time
  1107.      until it's all released at once when the loop is exited.
  1108.  
  1109. return LIST
  1110.      Returns from a subroutine with the value specified.  (Note that a
  1111.      subroutine can automatically return the value of the last
  1112.      expression evaluated.  That's the preferred method--use of an
  1113.      explicit `return' is a bit slower.)
  1114.  
  1115. wantarray
  1116.      Returns true if the context of the currently executing subroutine
  1117.      is looking for an array value.  Returns false if the context is
  1118.      looking for a scalar.
  1119.  
  1120.           return wantarray ? () : undef;
  1121.  
  1122. 
  1123. File: perl.info,  Node: Variable Functions,  Next: Miscellaneous Functions,  Prev: Subroutine Functions,  Up: Commands
  1124.  
  1125. Variable Functions
  1126. ==================
  1127.  
  1128. defined(EXPR)
  1129. defined EXPR
  1130.      Returns a boolean value saying whether the lvalue EXPR has a real
  1131.      value or not.  Many operations return the undefined value under
  1132.      exceptional conditions, such as end of file, uninitialized
  1133.      variable, system error and such.  This function allows you to
  1134.      distinguish between an undefined null string and a defined null
  1135.      string with operations that might return a real null string, in
  1136.      particular referencing elements of an array.  You may also check
  1137.      to see if arrays or subroutines exist.  Use on predefined
  1138.      variables is not guaranteed to produce intuitive results.
  1139.      Examples:
  1140.  
  1141.           print if defined $switch{'D'};
  1142.           print "$val\n" while defined($val = pop(@ary));
  1143.           die "Can't readlink $sym: $!"
  1144.                   unless defined($value = readlink $sym);
  1145.           eval '@foo = ()' if defined(@foo);
  1146.           die "No XYZ package defined" unless defined %_XYZ;
  1147.           sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
  1148.  
  1149.      See also `undef'.
  1150.  
  1151. reset(EXPR)
  1152. reset EXPR
  1153. reset
  1154.      Generally used in a `continue' block at the end of a loop to clear
  1155.      variables and reset `??' searches so that they work again.  The
  1156.      expression is interpreted as a list of single characters (hyphens
  1157.      allowed for ranges).  All variables and arrays beginning with one
  1158.      of those letters are reset to their pristine state.  If the
  1159.      expression is omitted, one-match searches (`?pattern?') are reset
  1160.      to match again.  Only resets variables or searches in the current
  1161.      package.  Always returns 1.  Examples:
  1162.  
  1163.           reset 'X';          # reset all X variables
  1164.           reset 'a-z';        # reset lower case variables
  1165.           reset;              # just reset `??' searches
  1166.  
  1167.      Note: resetting `A-Z' is not recommended since you'll wipe out your
  1168.      `ARGV' and `ENV' arrays.
  1169.  
  1170.      The use of reset on dbm associative arrays does not change the dbm
  1171.      file.  (It does, however, flush any entries cached by perl, which
  1172.      may be useful if you are sharing the dbm file.  Then again, maybe
  1173.      not.)
  1174.  
  1175. scalar(EXPR)
  1176.      Forces EXPR to be interpreted in a scalar context and returns the
  1177.      value of EXPR.
  1178.  
  1179. undef(EXPR)
  1180. undef EXPR
  1181. undef
  1182.      Undefines the value of EXPR, which must be an lvalue.  Use only on
  1183.      a scalar value, an entire array, or a subroutine name (using `&').
  1184.      (`undef' will probably not do what you expect on most predefined
  1185.      variables or dbm array values.)  Always returns the undefined
  1186.      value.  You can omit the EXPR, in which case nothing is undefined,
  1187.      but you still get an undefined value that you could, for instance,
  1188.      return from a subroutine.  Examples:
  1189.  
  1190.           undef $foo;
  1191.           undef $bar{'blurfl'};
  1192.           undef @ary;
  1193.           undef %assoc;
  1194.           undef &mysub;
  1195.           return (wantarray ? () : undef) if $they_blew_it;
  1196.  
  1197.