in reply to Hash ties
#!/usr/bin/perl package Database; my $database = {}; sub TIEHASH { my ($class, $key, $value, @options) = @_; # my $db = DBI->connect(...); # ... more database stuff $database->{"$key"} = $value; return bless $database; } sub FETCH { return $database->{"One"}; }
Seems a bit overkill but it shows what I mean, the hash value get's overwritten by the second tie, and I don't want it to. I thought of doing it with the anonymous hash for object properties but then what would I return in TIEHASH? Thanks.#!/usr/bin/perl use Database; my %one, %two; tie (%one, Database, "One", "hard"); print $one{"One"}; tie (%two, Database, "One", "soft"); print $two{"One"};
|
|---|