The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Data::Dumper::Names - Dump variables with names (no source filter)


Version 0.02


    use Data::Dumper::Names;

    my $foo = 3;
    my @bar = qw/this that/;
    warn Dumper($foo, \@bar);
    $foo = 3;
    @bar = (


Like Data::Dumper, this module automatically exports Dumper() unless a null import list is explicitly stated.

This module should be considered ALPHA.



 warn Dumper($foo, \@bar);

Dumper returns a string like Dumper but the variable names are prefixed for you. Unlike Data::Dumper::Simple, arrays and hashes must be passed by reference.



This module is an alternative to Data::Dumper::Simple. Many people like the aforementioned module but do not like the fact that it uses a source filter. In order to pull off the trick with this module, we use PadWalker. This introduces its own set of problems, not the least of which is that PadWalker uses undocumented features of the Perl internals and has an annoying tendency to break. Thus, if this module doesn't work on your machine you may have to go back to Data::Dumper::Simple.


Arrays and hashes, unlike in Data::Dumper::Simple, must be passed by reference. Unfortunately, this causes a problem:

 my $foo = \@array;
 warn Dumper( $foo, \@array );

Because of how pads work, there is no easy way to disambiguate between these two variables. Thus, Dumper may identify them as $foo or it may identify them as @array. If it misidentifies them, it should at least do so consistently for the individual call to Dumper. (For Perl 5.8 and after, subsequent calls to Dumper may have different results in the above case. This is because of how Perl handles hash ordering).

Unknown Variables

The easiest way to have things "just work" is to make sure that you can see the name of the variable in the Dumper call:

 warn Dumper($foo, \@bar); # good
 warn Dumper($_);          # probably will get output like $VAR1 = ...
 warn Dumper($bar[2]);     # probably will get output like $VAR1 = ...

Usually the output from Dumper will be something like this:

 $foo = 3;
 @bar = (

However, sometimes a $VAR1 or $VAR2 will creep in there. This happens if pass in anything but a named variable. For example:

 warn Dumper( $bar[2] ); # $VAR1 = ... can't figure out the name

We probably won't be able to figure out the name of the variable directly unless we took the time to walk all data structures in scope at the time Dumper is called. This is an expensive proposition, so we don't do that. It's possible we will be able to figure out that name, but only if the variable was assigned its value from a reference to a named variable.

 $bar[2] = \%foo;
 warn Dumper( $bar[2] );

Dumper, in the above example, will identify that variable as being %foo. That could be confusing if those lines are far apart.

 foreach ( @customer ) {
    print Dumper( $_ );

It should go without saying that the above will also probably not be able to name the variables.


Curtis "Ovid" Poe, <>


Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


See Data::Dumper and Data::Dumper::Simple.

Thanks to demerphq (Yves Orton) for finding a bug in how some variable names are reported. See Changes for details.


Copyright 2005 Curtis "Ovid" Poe, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.