Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

do

Reads, compiles, and executes a Perl file, returning the value of the last expression evaluated.

Unlike require, do FILE:

  • Always re-reads and re-executes the file (no %INC caching).
  • Does not die on failure; instead it returns undef and sets $@ to the error message.
  • Does not inherit caller lexicals (unlike eval STRING).
  • Evaluates the file in the current package context.

On success, returns the value of the last expression evaluated in the file and clears $@. On compilation or runtime error, returns undef and sets $@.

Synopsis

do "config.pl";
my $result = do "/path/to/file.pm";

See Also

require, eval, use