=head1 NAME perlfunc - Perl builtin functions =head1 DESCRIPTION The functions in this section can serve as terms in an expression. They fall into two major categories: list operators and named unary operators. These differ in their precedence relationship with a following comma. (See the precedence table in L.) List operators take more than one argument, while unary operators can never take more than one argument. Thus, a comma terminates the argument of a unary operator, but merely separates the arguments of a list operator. A unary operator generally provides a scalar context to its argument, while a list operator may provide either scalar and list contexts for its arguments. If it does both, the scalar arguments will be first, and the list argument will follow. (Note that there can ever be only one such list argument.) For instance, splice() has three scalar arguments followed by a list. In the syntax descriptions that follow, list operators that expect a list (and provide list context for the elements of the list) are shown with LIST as an argument. Such a list may consist of any combination of scalar arguments or list values; the list values will be included in the list as if each individual element were interpolated at that point in the list, forming a longer single-dimensional list value. Elements of the LIST should be separated by commas. Any function in the list below may be used either with or without parentheses around its arguments. (The syntax descriptions omit the parentheses.) If you use the parentheses, the simple (but occasionally surprising) rule is this: It I like a function, therefore it I a function, and precedence doesn't matter. Otherwise it's a list operator or unary operator, and precedence does matter. And whitespace between the function and left parenthesis doesn't count--so you need to be careful sometimes: print 1+2+4; # Prints 7. print(1+2) + 4; # Prints 3. print (1+2)+4; # Also prints 3! print +(1+2)+4; # Prints 7. print ((1+2)+4); # Prints 7. If you run Perl with the B<-w> switch it can warn you about this. For example, the third line above produces: print (...) interpreted as function at - line 1. Useless use of integer addition in void context at - line 1. For functions that can be used in either a scalar or list context, nonabortive failure is generally indicated in a scalar context by returning the undefined value, and in a list context by returning the null list. Remember the following important rule: There is B that relates the behavior of an expression in list context to its behavior in scalar context, or vice versa. It might do two totally different things. Each operator and function decides which sort of value it would be most appropriate to return in a scalar context. Some operators return the length of the list that would have been returned in list context. Some operators return the first value in the list. Some operators return the last value in the list. Some operators return a count of successful operations. In general, they do what you want, unless you want consistency. An named array in scalar context is quite different from what would at first glance appear to be a list in scalar context. You can't get a list like C<(1,2,3)> into being in scalar context, because the compiler knows the context at compile time. It would generate the scalar comma operator there, not the list construction version of the comma. That means it was never a list to start with. In general, functions in Perl that serve as wrappers for system calls of the same name (like chown(2), fork(2), closedir(2), etc.) all return true when they succeed and C otherwise, as is usually mentioned in the descriptions below. This is different from the C interfaces, which return C<-1> on failure. Exceptions to this rule are C, C, and C. System calls also set the special C<$!> variable on failure. Other functions do not, except accidentally. =head2 Perl Functions by Category Here are Perl's functions (including things that look like functions, like some keywords and named operators) arranged by category. Some functions appear in more than one place. =over =item Functions for SCALARs or strings C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C =item Regular expressions and pattern matching C, C, C, C, C, C, C =item Numeric functions C, C, C, C, C, C, C, C, C, C, C, C =item Functions for real @ARRAYs C, C, C, C, C =item Functions for list data C, C, C, C, C, C, C =item Functions for real %HASHes C, C, C, C, C =item Input and output functions C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C For more information about the portability of these functions, see L and other available platform-specific documentation. =head2 Alphabetical Listing of Perl Functions =over 8 =item I<-X> FILEHANDLE =item I<-X> EXPR =item I<-X> A file test, where X is one of the letters listed below. This unary operator takes one argument, either a filename or a filehandle, and tests the associated file to see if something is true about it. If the argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN. Unless otherwise documented, it returns C<1> for TRUE and C<''> for FALSE, or the undefined value if the file doesn't exist. Despite the funny names, precedence is the same as any other named unary operator, and the argument may be parenthesized like any other unary operator. The operator may be any of: X<-r>X<-w>X<-x>X<-o>X<-R>X<-W>X<-X>X<-O>X<-e>X<-z>X<-s>X<-f>X<-d>X<-l>X<-p> X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C> -r File is readable by effective uid/gid. -w File is writable by effective uid/gid. -x File is executable by effective uid/gid. -o File is owned by effective uid. -R File is readable by real uid/gid. -W File is writable by real uid/gid. -X File is executable by real uid/gid. -O File is owned by real uid. -e File exists. -z File has zero size. -s File has nonzero size (returns size). -f File is a plain file. -d File is a directory. -l File is a symbolic link. -p File is a named pipe (FIFO), or Filehandle is a pipe. -S File is a socket. -b File is a block special file. -c File is a character special file. -t Filehandle is opened to a tty. -u File has setuid bit set. -g File has setgid bit set. -k File has sticky bit set. -T File is a text file. -B File is a binary file (opposite of -T). -M Age of file in days when script started. -A Same for access time. -C Same for inode change time. Example: while (<>) { chop; next unless -f $_; # ignore specials #... } The interpretation of the file permission operators C<-r>, C<-R>, C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode of the file and the uids and gids of the user. There may be other reasons you can't actually read, write, or execute the file. Such reasons may be for example network filesystem access controls, ACLs (access control lists), read-only filesystems, and unrecognized executable formats. Also note that, for the superuser on the local filesystems, C<-r>, C<-R>, C<-w>, and C<-W> always return 1, and C<-x> and C<-X> return 1 if any execute bit is set in the mode. Scripts run by the superuser may thus need to do a stat() to determine the actual mode of the file, or temporarily set the uid to something else. If you are using ACLs, there is a pragma called C that may produce more accurate results than the bare stat() mode bits. When under the C the above-mentioned filetests will test whether the permission can (not) be granted using the access() family of system calls. Also note that the C<-x> and C<-X> may under this pragma return true even if there are no execute permission bits set (nor any extra execute permission ACLs). This strangeness is due to the underlying system calls' definitions. Read the documentation for the C pragma for more information. Note that C<-s/a/b/> does not do a negated substitution. Saying C<-exp($foo)> still works as expected, however--only single letters following a minus are interpreted as file tests. The C<-T> and C<-B> switches work as follows. The first block or so of the file is examined for odd characters such as strange control codes or characters with the high bit set. If too many strange characters (E30%) are found, it's a C<-B> file, otherwise it's a C<-T> file. Also, any file containing null in the first block is considered a binary file. If C<-T> or C<-B> is used on a filehandle, the current stdio buffer is examined rather than the first block. Both C<-T> and C<-B> return TRUE on a null file, or a file at EOF when testing a filehandle. Because you have to read a file to do the C<-T> test, on most occasions you want to use a C<-f> against the file first, as in C. If any of the file tests (or either the C or C operators) are given the special filehandle consisting of a solitary underline, then the stat structure of the previous file test (or stat operator) is used, saving a system call. (This doesn't work with C<-t>, and you need to remember that lstat() and C<-l> will leave values in the stat structure for the symbolic link, not the real file.) Example: print "Can do.\n" if -r $a || -w _ || -x _; stat($filename); print "Readable\n" if -r _; print "Writable\n" if -w _; print "Executable\n" if -x _; print "Setuid\n" if -u _; print "Setgid\n" if -g _; print "Sticky\n" if -k _; print "Text\n" if -T _; print "Binary\n" if -B _; =item abs VALUE =item abs Returns the absolute value of its argument. If VALUE is omitted, uses C<$_>. =item accept NEWSOCKET,GENERICSOCKET Accepts an incoming socket connect, just as the accept(2) system call does. Returns the packed address if it succeeded, FALSE otherwise. See example in L. =item alarm SECONDS =item alarm Arranges to have a SIGALRM delivered to this process after the specified number of seconds have elapsed. If SECONDS is not specified, the value stored in C<$_> is used. (On some machines, unfortunately, the elapsed time may be up to one second less than you specified because of how seconds are counted.) Only one timer may be counting at once. Each call disables the previous timer, and an argument of C<0> may be supplied to cancel the previous timer without starting a new one. The returned value is the amount of time remaining on the previous timer. For delays of finer granularity than one second, you may use Perl's C interface to access setitimer(2) if your system supports it, or else see L. It is usually a mistake to intermix C and C calls. If you want to use C to time out a system call you need to use an C/C pair. You can't rely on the alarm causing the system call to fail with C<$!> set to C because Perl sets up signal handlers to restart system calls on some systems. Using C/C always works, modulo the caveats given in L. eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm $timeout; $nread = sysread SOCKET, $buffer, $size; alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors # timed out } else { # didn't } =item atan2 Y,X Returns the arctangent of Y/X in the range -PI to PI. For the tangent operation, you may use the C function, or use the familiar relation: sub tan { sin($_[0]) / cos($_[0]) } =item bind SOCKET,NAME Binds a network address to a socket, just as the bind system call does. Returns TRUE if it succeeded, FALSE otherwise. NAME should be a packed address of the appropriate type for the socket. See the examples in L. =item binmode FILEHANDLE Arranges for the file to be read or written in "binary" mode in operating systems that distinguish between binary and text files. Files that are not in binary mode have CR LF sequences translated to LF on input and LF translated to CR LF on output. Binmode has no effect under Unix; in MS-DOS and similarly archaic systems, it may be imperative--otherwise your MS-DOS-damaged C library may mangle your file. The key distinction between systems that need C and those that don't is their text file formats. Systems like Unix, MacOS, and Plan9 that delimit lines with a single character, and that encode that character in C as C<"\n">, do not need C. The rest need it. If FILEHANDLE is an expression, the value is taken as the name of the filehandle. =item bless REF,CLASSNAME =item bless REF This function tells the thingy referenced by REF that it is now an object in the CLASSNAME package--or the current package if no CLASSNAME is specified, which is often the case. It returns the reference for convenience, because a C is often the last thing in a constructor. Always use the two-argument version if the function doing the blessing might be inherited by a derived class. See L and L for more about the blessing (and blessings) of objects. Consider always blessing objects in CLASSNAMEs that are mixed case. Namespaces with all lowercase names are considered reserved for Perl pragmata. Builtin types have all uppercase names, so to prevent confusion, it is best to avoid such package names as well. See L. =item caller EXPR =item caller Returns the context of the current subroutine call. In scalar context, returns the caller's package name if there is a caller, that is, if we're in a subroutine or C or C, and the undefined value otherwise. In list context, returns ($package, $filename, $line) = caller; With EXPR, it returns some extra information that the debugger uses to print a stack trace. The value of EXPR indicates how many call frames to go back before the current one. ($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require) = caller($i); Here C<$subroutine> may be C<"(eval)"> if the frame is not a subroutine call, but an C. In such a case additional elements C<$evaltext> and C<$is_require> are set: C<$is_require> is true if the frame is created by a C or C statement, C<$evaltext> contains the text of the C statement. In particular, for a C statement, C<$filename> is C<"(eval)">, but C<$evaltext> is undefined. (Note also that each C statement creates a C frame inside an C) frame. Furthermore, when called from within the DB package, caller returns more detailed information: it sets the list variable C<@DB::args> to be the arguments with which the subroutine was invoked. Be aware that the optimizer might have optimized call frames away before C had a chance to get the information. That means that C might not return information about the call frame you expect it do, for C 1>. In particular, C<@DB::args> might have information from the previous time C was called. =item chdir EXPR Changes the working directory to EXPR, if possible. If EXPR is omitted, changes to home directory. Returns TRUE upon success, FALSE otherwise. See example under C. =item chmod LIST Changes the permissions of a list of files. The first element of the list must be the numerical mode, which should probably be an octal number, and which definitely should I a string of octal digits: C<0644> is okay, C<'0644'> is not. Returns the number of files successfully changed. See also L, if all you have is a string. $cnt = chmod 0755, 'foo', 'bar'; chmod 0755, @executables; $mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to # --w----r-T $mode = '0644'; chmod oct($mode), 'foo'; # this is better $mode = 0644; chmod $mode, 'foo'; # this is best =item chomp VARIABLE =item chomp LIST =item chomp This is a slightly safer version of L. It removes any line ending that corresponds to the current value of C<$/> (also known as $INPUT_RECORD_SEPARATOR in the C module). It returns the total number of characters removed from all its arguments. It's often used to remove the newline from the end of an input record when you're worried that the final record may be missing its newline. When in paragraph mode (C<$/ = "">), it removes all trailing newlines from the string. If VARIABLE is omitted, it chomps C<$_>. Example: while (<>) { chomp; # avoid \n on last field @array = split(/:/); # ... } You can actually chomp anything that's an lvalue, including an assignment: chomp($cwd = `pwd`); chomp($answer = ); If you chomp a list, each element is chomped, and the total number of characters removed is returned. =item chop VARIABLE =item chop LIST =item chop Chops off the last character of a string and returns the character chopped. It's used primarily to remove the newline from the end of an input record, but is much more efficient than C because it neither scans nor copies the string. If VARIABLE is omitted, chops C<$_>. Example: while (<>) { chop; # avoid \n on last field @array = split(/:/); #... } You can actually chop anything that's an lvalue, including an assignment: chop($cwd = `pwd`); chop($answer = ); If you chop a list, each element is chopped. Only the value of the last C is returned. Note that C returns the last character. To return all but the last character, use C. =item chown LIST Changes the owner (and group) of a list of files. The first two elements of the list must be the I uid and gid, in that order. Returns the number of files successfully changed. $cnt = chown $uid, $gid, 'foo', 'bar'; chown $uid, $gid, @filenames; Here's an example that looks up nonnumeric uids in the passwd file: print "User: "; chop($user = ); print "Files: "; chop($pattern = ); ($login,$pass,$uid,$gid) = getpwnam($user) or die "$user not in passwd file"; @ary = glob($pattern); # expand filenames chown $uid, $gid, @ary; On most systems, you are not allowed to change the ownership of the file unless you're the superuser, although you should be able to change the group to any of your secondary groups. On insecure systems, these restrictions may be relaxed, but this is not a portable assumption. =item chr NUMBER =item chr Returns the character represented by that NUMBER in the character set. For example, C is C<"A"> in either ASCII or Unicode, and chr(0x263a) is a Unicode smiley face (but only within the scope of a C). For the reverse, use L. If NUMBER is omitted, uses C<$_>. =item chroot FILENAME =item chroot This function works like the system call by the same name: it makes the named directory the new root directory for all further pathnames that begin with a C<"/"> by your process and all its children. (It doesn't change your current working directory, which is unaffected.) For security reasons, this call is restricted to the superuser. If FILENAME is omitted, does a C to C<$_>. =item close FILEHANDLE =item close Closes the file or pipe associated with the file handle, returning TRUE only if stdio successfully flushes buffers and closes the system file descriptor. Closes the currently selected filehandle if the argument is omitted. You don't have to close FILEHANDLE if you are immediately going to do another C on it, because C will close it for you. (See C.) However, an explicit C on an input file resets the line counter (C<$.>), while the implicit close done by C does not. If the file handle came from a piped open C will additionally return FALSE if one of the other system calls involved fails or if the program exits with non-zero status. (If the only problem was that the program exited non-zero C<$!> will be set to C<0>.) Also, closing a pipe waits for the process executing on the pipe to complete, in case you want to look at the output of the pipe afterwards. Closing a pipe explicitly also puts the exit status value of the command into C<$?>. Example: open(OUTPUT, '|sort >foo') # pipe to sort or die "Can't start sort: $!"; #... # print stuff to output close OUTPUT # wait for sort to finish or warn $! ? "Error closing sort pipe: $!" : "Exit status $? from sort"; open(INPUT, 'foo') # get sort's results or die "Can't open 'foo' for input: $!"; FILEHANDLE may be an expression whose value can be used as an indirect filehandle, usually the real filehandle name. =item closedir DIRHANDLE Closes a directory opened by C and returns the success of that system call. DIRHANDLE may be an expression whose value can be used as an indirect dirhandle, usually the real dirhandle name. =item connect SOCKET,NAME Attempts to connect to a remote socket, just as the connect system call does. Returns TRUE if it succeeded, FALSE otherwise. NAME should be a packed address of the appropriate type for the socket. See the examples in L. =item continue BLOCK Actually a flow control statement rather than a function. If there is a C BLOCK attached to a BLOCK (typically in a C or C), it is always executed just before the conditional is about to be evaluated again, just like the third part of a C loop in C. Thus it can be used to increment a loop variable, even when the loop has been continued via the C statement (which is similar to the C C statement). C, C, or C may appear within a C block. C and C will behave as if they had been executed within the main block. So will C, but since it will execute a C block, it may be more entertaining. while (EXPR) { ### redo always comes here do_something; } continue { ### next always comes here do_something_else; # then back the top to re-check EXPR } ### last always comes here Omitting the C section is semantically equivalent to using an empty one, logically enough. In that case, C goes directly back to check the condition at the top of the loop. =item cos EXPR Returns the cosine of EXPR (expressed in radians). If EXPR is omitted, takes cosine of C<$_>. For the inverse cosine operation, you may use the C function, or use this relation: sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) } =item crypt PLAINTEXT,SALT Encrypts a string exactly like the crypt(3) function in the C library (assuming that you actually have a version there that has not been extirpated as a potential munition). This can prove useful for checking the password file for lousy passwords, amongst other things. Only the guys wearing white hats should do this. Note that C is intended to be a one-way function, much like breaking eggs to make an omelette. There is no (known) corresponding decrypt function. As a result, this function isn't all that useful for cryptography. (For that, see your nearby CPAN mirror.) When verifying an existing encrypted string you should use the encrypted text as the salt (like C). This allows your code to work with the standard C and with more exotic implementations. When choosing a new salt create a random two character string whose characters come from the set C<[./0-9A-Za-z]> (like C). Here's an example that makes sure that whoever runs this program knows their own password: $pwd = (getpwuid($<))[1]; system "stty -echo"; print "Password: "; chomp($word = ); print "\n"; system "stty echo"; if (crypt($word, $pwd) ne $pwd) { die "Sorry...\n"; } else { print "ok\n"; } Of course, typing in your own password to whoever asks you for it is unwise. =item dbmclose HASH [This function has been superseded by the C function.] Breaks the binding between a DBM file and a hash. =item dbmopen HASH,DBNAME,MODE [This function has been superseded by the C function.] This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a hash. HASH is the name of the hash. (Unlike normal C, the first argument is I a filehandle, even though it looks like one). DBNAME is the name of the database (without the F<.dir> or F<.pag> extension if any). If the database does not exist, it is created with protection specified by MODE (as modified by the C). If your system supports only the older DBM functions, you may perform only one C in your program. In older versions of Perl, if your system had neither DBM nor ndbm, calling C produced a fatal error; it now falls back to sdbm(3). If you don't have write access to the DBM file, you can only read hash variables, not set them. If you want to test whether you can write, either use file tests or try setting a dummy hash entry inside an C, which will trap the error. Note that functions such as C and C may return huge lists when used on large DBM files. You may prefer to use the C function to iterate over large DBM files. Example: # print out history file offsets dbmopen(%HIST,'/usr/lib/news/history',0666); while (($key,$val) = each %HIST) { print $key, ' = ', unpack('L',$val), "\n"; } dbmclose(%HIST); See also L for a more general description of the pros and cons of the various dbm approaches, as well as L for a particularly rich implementation. =item defined EXPR =item defined Returns a Boolean value telling whether EXPR has a value other than the undefined value C. If EXPR is not present, C<$_> will be checked. Many operations return C to indicate failure, end of file, system error, uninitialized variable, and other exceptional conditions. This function allows you to distinguish C from other values. (A simple Boolean test will not distinguish among C, zero, the empty string, and C<"0">, which are all equally false.) Note that since C is a valid scalar, its presence doesn't I indicate an exceptional condition: C returns C when its argument is an empty array, I when the element to return happens to be C. You may also use C to check whether a subroutine exists, by saying C without parentheses. On the other hand, use of C upon aggregates (hashes and arrays) is not guaranteed to produce intuitive results, and should probably be avoided. When used on a hash element, it tells you whether the value is defined, not whether the key exists in the hash. Use L for the latter purpose. Examples: print if defined $switch{'D'}; print "$val\n" while defined($val = pop(@ary)); die "Can't readlink $sym: $!" unless defined($value = readlink $sym); sub foo { defined &$bar ? &$bar(@_) : die "No bar"; } $debugging = 0 unless defined $debugging; Note: Many folks tend to overuse C, and then are surprised to discover that the number C<0> and C<""> (the zero-length string) are, in fact, defined values. For example, if you say "ab" =~ /a(.*)b/; The pattern match succeeds, and C<$1> is defined, despite the fact that it matched "nothing". But it didn't really match nothing--rather, it matched something that happened to be C<0> characters long. This is all very above-board and honest. When a function returns an undefined value, it's an admission that it couldn't give you an honest answer. So you should use C only when you're questioning the integrity of what you're trying to do. At other times, a simple comparison to C<0> or C<""> is what you want. Currently, using C on an entire array or hash reports whether memory for that aggregate has ever been allocated. So an array you set to the empty list appears undefined initially, and one that once was full and that you then set to the empty list still appears defined. You should instead use a simple test for size: if (@an_array) { print "has array elements\n" } if (%a_hash) { print "has hash members\n" } Using C on these, however, does clear their memory and then report them as not defined anymore, but you shouldn't do that unless you don't plan to use them again, because it saves time when you load them up again to have memory already ready to be filled. The normal way to free up space used by an aggregate is to assign the empty list. This counterintuitive behavior of C on aggregates may be changed, fixed, or broken in a future release of Perl. See also L, L, L. =item delete EXPR Deletes the specified key(s) and their associated values from a hash. For each key, returns the deleted value associated with that key, or the undefined value if there was no such key. Deleting from C<$ENV{}> modifies the environment. Deleting from a hash tied to a DBM file deletes the entry from the DBM file. (But deleting from a Cd hash doesn't necessarily return anything.) The following deletes all the values of a hash: foreach $key (keys %HASH) { delete $HASH{$key}; } And so does this: delete @HASH{keys %HASH} (But both of these are slower than just assigning the empty list, or using C.) Note that the EXPR can be arbitrarily complicated as long as the final operation is a hash element lookup or hash slice: delete $ref->[$x][$y]{$key}; delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys}; =item die LIST Outside an C, prints the value of LIST to C and exits with the current value of C<$!> (errno). If C<$!> is C<0>, exits with the value of C<($? EE 8)> (backtick `command` status). If C<($? EE 8)> is C<0>, exits with C<255>. Inside an C the error message is stuffed into C<$@> and the C is terminated with the undefined value. This makes C the way to raise an exception. Equivalent examples: die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news'; chdir '/usr/spool/news' or die "Can't cd to spool: $!\n" If the value of EXPR does not end in a newline, the current script line number and input line number (if any) are also printed, and a newline is supplied. Hint: sometimes appending C<", stopped"> to your message will cause it to make better sense when the string C<"at foo line 123"> is appended. Suppose you are running script "canasta". die "/etc/games is no good"; die "/etc/games is no good, stopped"; produce, respectively /etc/games is no good at canasta line 123. /etc/games is no good, stopped at canasta line 123. See also C and C. If LIST is empty and C<$@> already contains a value (typically from a previous eval) that value is reused after appending C<"\t...propagated">. This is useful for propagating exceptions: eval { ... }; die unless $@ =~ /Expected exception/; If C<$@> is empty then the string C<"Died"> is used. You can arrange for a callback to be run just before the C does its deed, by setting the C<$SIG{__DIE__}> hook. The associated handler will be called with the error text and can change the error message, if it sees fit, by calling C again. See L for details on setting C<%SIG> entries, and L<"eval BLOCK"> for some examples. Note that the C<$SIG{__DIE__}> hook is called even inside eval()ed blocks/strings. If one wants the hook to do nothing in such situations, put die @_ if $^S; as the first line of the handler (see L). =item do BLOCK Not really a function. Returns the value of the last command in the sequence of commands indicated by BLOCK. When modified by a loop modifier, executes the BLOCK once before testing the loop condition. (On other statements the loop modifiers test the conditional first.) C does I count as a loop, so the loop control statements C, C or C cannot be used to leave or restart the block. =item do SUBROUTINE(LIST) A deprecated form of subroutine call. See L. =item do EXPR Uses the value of EXPR as a filename and executes the contents of the file as a Perl script. Its primary use is to include subroutines from a Perl subroutine library. do 'stat.pl'; is just like scalar eval `cat stat.pl`; except that it's more efficient and concise, keeps track of the current filename for error messages, and searches all the B<-I> libraries if the file isn't in the current directory (see also the @INC array in L). It is also different in how code evaluated with C doesn't see lexicals in the enclosing scope like C does. It's the same, however, in that it does reparse the file every time you call it, so you probably don't want to do this inside a loop. If C cannot read the file, it returns undef and sets C<$!> to the error. If C can read the file but cannot compile it, it returns undef and sets an error message in C<$@>. If the file is successfully compiled, C returns the value of the last expression evaluated. Note that inclusion of library modules is better done with the C and C operators, which also do automatic error checking and raise an exception if there's a problem. You might like to use C to read in a program configuration file. Manual error checking can be done this way: # read in config files: system first, then user for $file ("/share/prog/defaults.rc", "$ENV{HOME}/.someprogrc") { unless ($return = do $file) { warn "couldn't parse $file: $@" if $@; warn "couldn't do $file: $!" unless defined $return; warn "couldn't run $file" unless $return; } } =item dump LABEL This causes an immediate core dump. Primarily this is so that you can use the B program to turn your core dump into an executable binary after having initialized all your variables at the beginning of the program. When the new binary is executed it will begin by executing a C (with all the restrictions that C suffers). Think of it as a goto with an intervening core dump and reincarnation. If C