The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


Primeval - terse variable dumping


version 0.02


    use Primeval;

    my $foo = 5;
    my @bar = 1..10;
    our %baz = (a => 1, b => 2);

    prim{eval} '$foo @bar %baz';


    $foo: 5
    @bar: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    %baz: {a => 1, b => 2}


    prim  # always called as prim{eval}


prim{eval} LIST

takes a list of variable names, prints out the names along with their values. each element of the argument list is split on white-space.

while actually a subroutine named prim the block {eval} must always be passed to prim as the first argument. this code block is used to peek into the calling scope to fetch the values for lexical variables. using this code block to access the caller's scope allows this module to have no external dependencies (normally PadWalker would be required to peek into a lexical scope)

the arguments are checked to make sure they look like perl variable names, so you don't have to worry about anything accidentally making it into an eval that you wouldn't want to.

prim{eval} will normally only print the first level of an array or hash using a simple internal serialization routine. for full recursive printing, arrays and hashes can be passed to Data::Dumper by setting $Primeval::DUMP = 1

prim{eval} will return a string instead of printing if $Primeval::RETURN is set to a true value.

if you use prim{eval} in a subroutine with closed over variables, just make sure that you use every variable passed to prim{eval} somewhere else in the subroutine. otherwise, perl's garbage collector will sweep up the variables too early.


Eric Strom, <asg at>


prim{eval} only works correctly with closures in perl 5.10+

please report any bugs or feature requests to bug-primeval at, 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.


copyright 2011 Eric Strom.

this program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

see for more information.