Perl 5 version 8.8 documentation
- do BLOCK
Not really a function. Returns the value of the last command in the sequence of commands indicated by BLOCK. When modified by the
untilloop modifier, executes the BLOCK once before testing the loop condition. (On other statements the loop modifiers test the conditional first.)
- do SUBROUTINE(LIST)
This form of subroutine call is deprecated. See perlsub.
- do EXPR
Uses the value of EXPR as a filename and executes the contents of the file as a Perl script.
- do 'stat.pl';
is just like
- eval `cat stat.pl`;
except that it's more efficient and concise, keeps track of the current filename for error messages, searches the @INC directories, and updates
%INCif the file is found. See Predefined Names in perlvar for these variables. It also differs in that code evaluated with
do FILENAMEcannot see lexicals in the enclosing scope;
eval STRINGdoes. 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.
docannot read the file, it returns undef and sets
$!to the error. If
docan read the file but cannot compile it, it returns undef and sets an error message in
$@. If the file is successfully compiled,
doreturns the value of the last expression evaluated.
You might like to use
doto read in a program configuration file. Manual error checking can be done this way: