[Israel.pm] Perl Advocacy
bruck at actcom.net.il
Wed Dec 29 14:23:22 PST 2004
Gabor Szabo wrote:
> I am not that coninced that having a unified view of hashes and array
> (which are then basically hashes with only numbers as keys)
> is a bad thing. It does hide some complexity (and produces a speed
> penalty I guess).
> Nothing would happen if
> keys %myhash;
> would always return the keys sorted numerically.
I don't know the php internals on this, but the way it looks from the
php programmer's pov is that adding a key to a hash implicitly creates a
numerical index for that key.
Off hand I can think on one srting example where I'd a hash with
numerical keys rather than an array.
Suppose I need to retrieve a set of values, each is associated with a
number and I want to sort them.
One way is to stored each value at $array[$number]
Now suppose I know the numbers are not consecutive, I also know that for
some cases I'll have big gaps. F'rinstance
Using an array for that means that I've got a big empty array. Using a
hash with those numbers as keys gives me the results I want with a much
lower storage overhead.
If hashes and arrays are unified, I don't have that option.
> They still cannot have arrays as keys to arrays so Python must be
> superior to PHP as well.
> Perl mailing list
> Perl at perl.org.il
More information about the Perl