in reply to Re: Re: Marking an array as already seen ('~'magic virtual table)
in thread Marking an array as already seen
To get the value bound to the variable, I'm simply returning it's pointer stored in mg_ptr. See the Magic Virtual Tables section in perldoc:perlguts for a better explanation (It's late and I'm bug-eyed tired). I'm only implementing free though it could be extended to open up the other functions. I probably will do that. If I did, let's say you were trying to make a cache of the output of some larger process, you would be able to add a callback to the data structure via set && clear magic that would invalidate that part of the cache when updated and it wouldn't require any direct action by the user.Function pointer Action taken ---------------- ------------ svt_get Do something after the value of the SV is retr +ieved. svt_set Do something after the SV is assigned a value. svt_len Report on the SV's length. svt_clear Clear something the SV represents. svt_free Free any extra storage associated with the SV.
Not a compelling example above but I can think of some better ones which I'll post when it's cleaned up. If you think about how matching works and how it tracks where it is in a string, well you can do the same thing with any sub now without trying to compute unique keys from caller() + data and storing it in a hash. Lazily processing lists non-destructively is another good example.attach ( $somepointer, { seen=>1 }, 'opt_name_to_avoid_collision') or + die "Couldn't attach; # Later on... my $attached = attach($somepointer); $attached->{bar}= uc $attached->{bar};
|
|---|