Devel::TraceVars - Print each line of code with variables evaluated


    $ perl -d:TraceVars[+MODE[OPTIONS]] program [arguments]

Where MODE can be modules or custom.

If modules mode is selected then the output will only include the lines that are provided by the given modules.

Modules can be added by separating them by commas ,. By default the module main is assumed to be included. Optionally, the wildcard * can be used to indicate any module that matches the given pattern. Thus, the entry Net::SSH::* will match all modules that start with Net::SSH.

NOTE: The wild card handling works only if it's used as the last character. Using the following pattern Net::*::Perl isn't supported yet.

If non-cpan is used then output will exclude all files that are provided by CPAN. At present, a module is considered to be provided by CPAN if the module is loaded from the Perl include path as designated by $Config{installarchlib}.

If no mode is specified then all output lines are printed.


perl -d:TraceVars

Prints all lines.

perl -d:TraceVars+modules

Defaults to print only all lines of the package main which usually means all lines in the main program. The package main is the default package used by perl when no package is specified in the code.

perl -d:TraceVars+modules,Net::SSH,Digest::*

Prints only information from the module Net::SSH, and from any module whose name starts with Digest.

perl -d:TraceVars+noncpan

Prints only lines that are provided by perl files that aren't stored in the default folder where all CPAN modules are installed.


If you run your program with perl -d:TraceVars program, this module will print the current line of code being executed to standard error just before each line is executed. The contents of all scalar variables will be evaluated and displayed as well. All leading and trailing spaces will be removed from each line.


The following methods are available.


Called by perl when this module is first loaded.


This is the important part. Perl calls this method before each line is executed.

evaluate($package, $variable)

Tries to evaluate the content of the given variable.

  • $package

    The package's scope where the variable was used.

  • $variable

    The variable name to evaluate.

Returns the variable's content.


Probably the code won't work with Perl's special variables. Sometimes perl seems to core dump when using this module.




Emmanuel Rodriguez <> based on a shameless copy of Devel::Trace .