develooper Front page | perl.perl5.porters | Postings from July 2001

[ID 20010704.006] Data::Dumper Purity mode t/dumper.t fails ifslightly rearranged

Thread Next
July 4, 2001 13:11
[ID 20010704.006] Data::Dumper Purity mode t/dumper.t fails ifslightly rearranged
Message ID:

Perl code:

    use Data::Dumper;
    my @dogs = ( 'Fido', 'Wags' );
    my %kennel = (
      First => \$dogs[0],
      Second =>  \$dogs[1],
    $dogs[2] = \%kennel;
    my $mutts = \%kennel;

    print "CORRECT:\n";
    print Data::Dumper->new(
      [\@dogs, \%kennel, $mutts],
      [qw($dogs $kennel $mutts)])->Purity(1)->Dump;

    print "WRONG:\n";
    print Data::Dumper->new(
      [\%kennel, \@dogs, $mutts],
      [qw($kennel $dogs $mutts)])->Purity(1)->Dump;


    $dogs = [
                'First' => '',
                'Second' => ''
    $dogs->[2]{'First'} = \$dogs->[0];
    $dogs->[2]{'Second'} = \$dogs->[1];
    $kennel = $dogs->[2];
    $mutts = $dogs->[2];
    $kennel = {
                'First' => \'Fido',
                'Second' => \'Wags'
    $dogs = [
    $dogs->[2] = $kennel;
    $mutts = $kennel;

The WRONG is wrong because the $dogs->[0] is set to a separate copy of
the 'Fido' string, and no longer is associated with $kennel->{First}.
Ditto for 'Wags'.

I'm not sure how to fix this... you really need to dump $dogs before
$kennel here so you can take a reference to the array element in
place.  Or it has to be patched up afterward.  I'm turning Purity on,
which is usually pretty good about constructing the patchups.  But it
wasn't sufficient here.

Site configuration information for perl 5.00503:

Configured by root at Sat May 15 13:27:02 PDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
    osname=linux, osvers=2.0.35, archname=i686-linux
    uname='linux 2.0.35 #10 mon nov 23 19:37:42 pst 1998 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
    cc='cc', optimize='-O2', gccversion=egcs-2.91.60 19981201 (egcs-1.1.1 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:

@INC for perl 5.00503:

Environment for perl 5.00503:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About