Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm guessing that I'm doing something blatantly wrong, but I'd like to hide $foo from the Dump():
$ perl -MData::Dumper -e '$foo=[1..5]; $bar=[[6..10], $foo];$d=Data::D +umper->new([$bar]); $d->Seen({foo => $foo}); print $d->Dump' $VAR1 = [ [ 6, 7, 8, 9, 10 ], [ 1, 2, 3, 4, 5 ] ];
Any suggestions? This is perl, v5.8.8 built for amd64-freebsd Thanks.

Replies are listed 'Best First'.
Re: Data::Dumper not Seen()ing variables
by ikegami (Patriarch) on Nov 02, 2006 at 08:00 UTC

    After some debugging, I found that a bug was introduced in a recent version of Data::Dumper (i.e. after 2.121_04 / perl 5.8.7, but no later than 2.121_08 / perl 5.8.8). Fortunately, the workaround is easy: Call Data::Dumper::init_refaddr_format() before calling Seen. It only needs to be called once, but it can safely be called multiple times.

    use Data::Dumper (); my $foo = [1..5]; my $bar = [ [6..10], $foo ]; Data::Dumper::init_refaddr_format() # Workaround if *Data::Dumper::init_refaddr_format{CODE}; # Backwards compat my $d = Data::Dumper->new([ $bar ], [ '$bar' ]); $d->Seen({ '$foo' => $foo }); print $d->Dump();
    $bar = [ [ 6, 7, 8, 9, 10 ], $foo ];

    Update: This bug has been submitted as rt.cpan.org ticket 22766.

      Cool. Thanks
Re: Data::Dumper not Seen()ing variables
by sili (Initiate) on Nov 02, 2006 at 07:34 UTC
    (this my post... I didn't realize I wasn't logged in...) Daveman on freenode/#perl tried the same code and it appears to work fine (as expected). After some testing it seems to work on i386 architectures. This explains why I could have sworn the code was working before - I upgraded my server recently. I've got a feeling it's got something to do with:
    sub format_refaddr { require Scalar::Util; sprintf our $refaddr_format, Scalar::Util::refaddr(shift); }
    in Dumper.pm...
      On second thought, it's probably something in Dumper.xs. Scary stuff... maybe I'll just ditch USE_64_BIT_ALL and perlbug