On Mon Feb 23 11:18:23 2004, andrew@pimlott.net wrote: > > This is a bug report for perl from andrew@pimlott.net, > generated with the help of perlbug 1.34 running under perl v5.8.2. > > > ----------------------------------------------------------------- > [Please enter your report here] > > The following amusing function works: > > sub assign { $_[0] = $_[1] } > assign $foo => 1; > assign $foo{bar} => 1; > > In particular, in the last line, the hash element is autovivified by > the > assignment to the alias $_[0]. The following doesn't: > > sub maitai { tie $_[0] => 'MaiTai' } > maitai $foo; # ok > maitai $foo{bar}; # not ok > > $foo gets tied as expected, but $foo{bar} doesn't. Evidently, > whatever got > tied was dissociated from the hash element. This can be repaired with > > sub maitai { tie $_[0], 'MaiTai' } > $foo{bar} = undef; > maitai $foo{bar}; # ok > > However, this doesn't do it: > > sub maitai { $_[0] = 'DUMMY'; tie $_[0], 'MaiTai' } > maitai $foo{bar}; # $foo{bar} eq 'DUMMY' !! > > Last, > > tie $foo{bar} => 'MaiTai'; > > works fine. So the problem appears to be autovivifying, through an > alias, > in tie. It would be cool if this worked. > > Here is a tie implementation to test with: > > package MaiTai; > sub TIESCALAR { bless {} => MaiTai; } > sub FETCH { 'TIED' } I am in the middle of fixing this, but I have run into something interesting. Obviously sub { tie $_[0]... } ->($h{nonexistent}) should vivify the element. But should tied $_[0] vivify it? What about untie? These two functions do already autovivify in another way: $ ./perl -lIlib -e 'tied %$_; print $_' HASH(0x7fa2640052b8) $ ./perl -lIlib -e 'untie %$_; print $_' HASH(0x7f8d688052b8) Should they? It makes some sense for untie to put its argument in vivifying context, since it modifies it, though it would work just as well without autovivifying. To me, it doesn’t make sense that tied() should autovivify at all. However tied %$_ works, should the same rules apply to tied $_[0] where $_[0] represents a nonexistent element? -- Father Chrysostomos --- via perlbug: queue: perl5 status: open https://rt.perl.org:443/rt3/Ticket/Display.html?id=27010Thread Previous | Thread Next