Masem has asked for the wisdom of the Perl Monks concerning the following question:
In otherwords, I'd want the following code to be valid:
Now, if $obj is just a hash, the hash reference will work, but the array reference will give me problems. Of course, just using an array loses the meanful names.my $obj = do_stuff_from_my_module(); my $name = $obj->[2]; # Assume name is the 3rd element # # OR!!! # my $name = $obj->{ name };
If you look at a module like Net::Servent which trying to offer a similar interface, the names that I'd be using in my hash keys are now moved to method names, something I'm not thrilled about doing. I'd rather have the hash/array to be 'consistent' with the fact that this is just a data structure with no methods associated with it.
One thing that should be pointed out is that none of the names for the name will be solely numbers; this could be useful in distinguishing if the developer wants the array or the hash reference.
Is it possible to create a variable tied as both an array and a hash at the same time? Or is there some other approach one could use for this? Or is this an impossible task in perl?
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important
|
|---|