On Jun 21, 2005, at 8:33 PM, Sisyphus wrote:


----- Original Message -----
From: "Eric Wilhelm" <[EMAIL PROTECTED]>
To: <inline@perl.org>
Sent: Wednesday, June 22, 2005 2:32 AM
Subject: Re: Accessing info contained in objects


perldoc perltie
perldoc Tie::Array


Read the first a few times (never read the second) - totally clueless as to what it means but, in view of what you've written below, it looks like I'll
have to decipher it :-)

That man page is needlessly obscure.  Here's all you need to know:

{
 my $foo;
 tie $foo, "MyPack";  # Calls MyPack::TIESCALAR()
 print $foo;  # Calls MyPack::FETCH()
 $foo = 7;    # Calls MyPack::STORE()
}  # Calls MyPack::DESTROY()

You write the methods TIESCALAR, FETCH, STORE, and DESTROY (and some others if you want).

In the TIESCALAR method, have it return an object (blessed reference) with whatever information you want. That object will be passed as the first argument to the FETCH, STORE, and DESTROY methods.

If you want to get your hands on that object outside the MyPack:: methods, you can call tied($foo), or catch the return value of the tie() function.

 -Ken

Reply via email to