Open p5pRT opened 23 years ago
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;
Output:
CORRECT: $dogs = [ 'Fido'\, 'Wags'\, { 'First' => ''\, 'Second' => '' } ]; $dogs->[2]{'First'} = \$dogs->[0]; $dogs->[2]{'Second'} = \$dogs->[1]; $kennel = $dogs->[2]; $mutts = $dogs->[2]; WRONG: $kennel = { 'First' => \'Fido'\, 'Second' => \'Wags' }; $dogs = [ ${$kennel->{'First'}}\, ${$kennel->{'Second'}}\, {} ]; $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: Platform: osname=linux\, osvers=2.0.35\, archname=i686-linux uname='linux halfdome.holdit.com 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 Compiler: 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: /usr/lib/perl5/5.00503/i686-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i686-linux /usr/lib/perl5/site_perl/5.005 .
Environment for perl 5.00503: HOME=/home/merlyn LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/merlyn/bin:/usr/local/bin:/bin:/usr/bin PERL_BADLANG (unset) SHELL=/bin/tcsh
Similar results on 5.12.0.
On Wed Jul 04 06:11:31 2001\, merlyn@stonehenge.com wrote:
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;
Output:
CORRECT​: $dogs = \[ 'Fido'\, 'Wags'\, \{ 'First' => ''\, 'Second' => '' \} \]; $dogs\->\[2\]\{'First'\} = \\$dogs\->\[0\]; $dogs\->\[2\]\{'Second'\} = \\$dogs\->\[1\]; $kennel = $dogs\->\[2\]; $mutts = $dogs\->\[2\]; WRONG​: $kennel = \{ 'First' => \\'Fido'\, 'Second' => \\'Wags' \}; $dogs = \[ $\{$kennel\->\{'First'\}\}\, $\{$kennel\->\{'Second'\}\}\, \{\} \]; $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.
-- Alexandr Ciornii\, http://chorny.net
Similar results on 5.12.0.
On Wed Jul 04 06:11:31 2001\, merlyn@stonehenge.com wrote:
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;
Output:
CORRECT​: $dogs = \[ 'Fido'\, 'Wags'\, \{ 'First' => ''\, 'Second' => '' \} \]; $dogs\->\[2\]\{'First'\} = \\$dogs\->\[0\]; $dogs\->\[2\]\{'Second'\} = \\$dogs\->\[1\]; $kennel = $dogs\->\[2\]; $mutts = $dogs\->\[2\]; WRONG​: $kennel = \{ 'First' => \\'Fido'\, 'Second' => \\'Wags' \}; $dogs = \[ $\{$kennel\->\{'First'\}\}\, $\{$kennel\->\{'Second'\}\}\, \{\} \]; $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.
-- Alexandr Ciornii\, http://chorny.net
Migrated from rt.perl.org#7233 (status was 'open')
Searchable as RT7233$