Ovid has asked for the wisdom of the Perl Monks concerning the following question:
Now we can use an array as either a hash or array, supposedly getting the best of both worlds. Of course, this really needs both a hash lookup and an array lookup and thus has extra overhead unless we use the fields module. And, of course, deleting keys is problematic, and the syntax is confusing, and...use warnings; use strict; my $ph = [ { alpha => 1, beta => 2, gamma => 3, delta => 4, epsilon => + 5 }, #hashref "val a", "val b", "val c", "val d", "val e" ]; + # maps to these values # Print some of the elements print $ph->[1], "\n"; print $ph->{ alpha }, "\n"; print $ph->{ epsilon }, "\n"; # Let's add an element # Note the amount of work involved (though this can be done on two lin +es) # We can't autovivify an entry!! $ph->[ $ph->[ 0 ]->{ omega } = @{ $ph } ] = "The real last val"; print $ph->{ omega };
This leads me to wonder... what problem do pseudo-hashes solve? I know there's the annoyance with a regular hash autovivifying hash entries. Pseudo-hashes don't allow for autovivification of entries and can prevent subtle logic problems. But is this the only benefit? And is it potent enough to justify the extra work involved with creating one?
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Are pseudo-hashes worth the effort?
by autark (Friar) on Dec 13, 2000 at 05:54 UTC | |
by Dominus (Parson) on Dec 14, 2000 at 09:39 UTC | |
|
Re (tilly) 1: Are pseudo-hashes worth the effort?
by tilly (Archbishop) on Dec 13, 2000 at 05:53 UTC | |
|
Re: Are pseudo-hashes worth the effort?
by Dominus (Parson) on Dec 14, 2000 at 09:36 UTC |