Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
We don't bite newbies here... much
 
PerlMonks  

Tying package-variable hashes

by premchai21 (Curate)
on Nov 09, 2001 at 19:36 UTC ( [id://124466]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

premchai21 has asked for the wisdom of the Perl Monks concerning the following question:

Suppose I have a module that ties hashes, say Tie::Hash::Xyzzy. Now I do this:

package main; # (not necessarily explicit) tie %::, 'Tie::Hash::Xyzzy';

I've verified that when this is done, TIEHASH and DESTROY both get called at the right times, but I cannot figure out how and/or whether it is possible to actually use the package-variable hash as tied (I can't figure out how to tiewise-invoke STORE, FETCH, etc.) and what effect this would have (Tying to the object access to all variables in the package?) -- anymonk know how exactly this works?

Replies are listed 'Best First'.
Re: Tying package-variable hashes
by japhy (Canon) on Nov 09, 2001 at 19:48 UTC
    Well, Perl doesn't use Perl's data structures for working with the symbol table, it uses perl's. It doesn't convert things like $foo = 1 into ${ $main::{foo} } = 1, because that'd be too damn slow. So I'm afraid you can't really do what you're trying to do, unless you tie() EVERY variable you make into a special monitoring class.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Oh, I'm not trying to do anything in particular. I was just wondering whether there was a particular way this worked, and/or a particular reason for it working that way. Your post does however provide some insight. Thank you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://124466]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.