DO

NAME
SYNOPSIS
DESCRIPTION

NAME

do - turn a BLOCK into a TERM

SYNOPSIS

do BLOCK

do SUBROUTINE(LIST)

do EXPR

DESCRIPTION

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.)

A deprecated form of subroutine call. See the perlsub manpage.

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, more concise, keeps track of the current filename for error messages, and searches all the -I libraries if the file isn’t in the current directory (see also the @INC array in the section on Predefined Names in the perlvar manpage). 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.

Note that inclusion of library modules is better done with the use() and require() operators, which also do error checking and raise an exception if there’s a problem.