On Mon, Feb 17, 2003 at 07:35:10PM +0000, Dave Mitchell wrote: > On Mon, Feb 17, 2003 at 11:07:51AM -0500, Mark Mielke wrote: > > [ ... Why doesn't *b = *a keep the reference? ... ] > No, what you have is a stash with 2 entries 'a' and 'b', both of which > refer to the same GV. The sv entry of that GV used to point to the tied > SV, and now points to \1. > If instead you take a reference to $a, it works: > sub DESTROY { print "DESTROY called\n" } > sub TIESCALAR { bless [] } > sub FETCH { print "FETCH called (@_)\n"; $b = \$a; *a = \1, 55 } Quite right. Thanks! (For some reason I was thinking that *b=*a copied the GV...) > > It would be nice to be able to set up demand-loadable scalars just as > > it is possible to set up demand-loadable subroutines, however, if it > > looks like this will just be too much trouble, I'll stop asking > > embarassing questions. :-) > I must confess that I can't currently thing of a way of doing this :-( Assuming that the snippet above continues to work, I consider it a satisfactory work-around. The tie() sits in memory, but it never gets accessed again. The critical path only accesses the tie() the first time through. I'm happy. :-) mark -- mark@mielke.cc/markm@ncf.ca/markm@nortelnetworks.com __________________________ . . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder |\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | | | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada One ring to rule them all, one ring to find them, one ring to bring them all and in the darkness bind them... http://mark.mielke.cc/Thread Previous | Thread Next