"be consistent" | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Dear monks, suppose I wanted to create a tied hash class that supported storing multiple values per each key. Internally, this can be implemented by storing all values in an array (keeping in mind situations where the user may want to store array references as well). However, when inserting new values into the hash, is it possible to force Perl to evaluate $hash{$key} = @values; as $hash->STORE($key, @values);? If not, then the only two ways to insert multiple values at a time are
The first option is a bit clumsy, and the latter won't work if you want to be able to store array references in the hash. My gut feeling is that there is no way around this, as the tied hash interface is defined as STORE(this, key, value), and besides that, the assignment is always parsed in scalar context for hashes. (Right?) One way around it might be using overloading and lvalue subroutines (i.e. $hash{$key} would be overloaded syntax for $hash->store($key), where store() is an lvalue subroutine), but that doesn't seem elegant or, in fact, even a possible solution.
-- In reply to Tied hashes: multiple parameters to STORE()? by vrk
|
|