From: Oren Ben-K. <or...@ri...> - 2001-11-12 11:36:37
|
Clark C . Evans [mailto:cc...@cl...] wrote: > | Perhaps casting the above in C++ would make things clearer: (value3 should have been value2 everywhere)... > | I *can* extract the array and the index... > Really now... Well, at least the index, given the array. > What does this prove? How, given only value2 can > I construct the array? *boggles* It proves that value2 != value1. That's the issue. Forget about automatically finding the array. Though it *is* possible: my $t = 'text'; $a = []; $a->[0] = $t; $a->[1] = \$t; $a->[2] = \$a->[0]; print Data::Dumper->Dump([ $a ]), "\n"; Output: $VAR1 = [ 'text', \'text', \$VAR1->[0] ]; Pray tell me how the (&*%^&* did Data::Dumper know that the last references was to be serialized the way it was? Obviously Data::Dumper *DID* find out that it is a reference-to-sequence-entry-number-0, right? Now, how do we write the above in YAML? > I'm not convinced that if you dump a member of > an array, that the array it is contained in must > also be dumped. This is your assertion, no? Seems that way. Data::Dumper tries to avoid it, and hence has a bug: my $t = 'text'; $a = []; $a->[0] = $t; $a->[1] = \$t; $b = [ \$a->[0] ]; print Data::Dumper->Dump([ $b, $a ]), "\n"; eval Data::Dumper->Dump([ $b, $a ]), "\n"; $a->[0] = 'new'; $VAR1->[0] = 'new'; print "'", ${$b->[0]}, "' != '", ${$VAR2->[0]}, "'\n"; Output: $VAR1 = [ # Note Data::Dumper treats this # as a normal reference to scalar. # Maybe because it didn't see 'a' yet # so it *couldn't even know* it was # anything else? \'text' ]; $VAR2 = [ # It now sees 'a' and tries to # recover. Too late! ${$VAR1->[0]}, \'text' ]; # So, Data::Dumper didn't # reconstruct the right data # structure. Oops! 'new' != '' This is nasty. Really nasty. I'd love to hear Larry's explanation (why did he give references this strange semantics?). My proposal would solve it: b: - !ref - &1 - &2 text - !ref = : *2 - 0 # At this point you are free # to serialize it or not, as # you wish: a: &1 As you rightly point out, this requires placing all of 'a' inside the serialization, even if it doesn't otherwise appear in the stream. OK, it isn't pretty, but it works. It is an exotic case anyway... > *boggles* No arguments there. By *necessary* boggles... Have fun, Oren Ben-Kiki |