in reply to HASH keys preserve class ?
Hash entries (values) can be anything, including objects.
Hash keys can only be strings.
If you need objects for keys, have a look at Tie::RefHash.
Update: Here's an example of storing an object:
{ package MyClass; sub new { bless {}, shift } sub doit { print("Method called\n"); } } my $o = MyClass->new(); my %hash = ( object => $o ); $hash{object}->doit(); # Prints "Method called"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HASH keys preserve class ?
by Limbic~Region (Chancellor) on Oct 04, 2006 at 12:42 UTC | |
by ikegami (Patriarch) on Oct 04, 2006 at 15:26 UTC | |
by Limbic~Region (Chancellor) on Oct 04, 2006 at 15:38 UTC | |
by BrowserUk (Patriarch) on Oct 04, 2006 at 16:19 UTC |