Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

RE: My views on pseudohashes

by jrsmith (Pilgrim)
on Jun 23, 2000 at 22:40 UTC ( #19642=note: print w/ replies, xml ) Need Help??


in reply to My views on pseudohashes

what exactly is a pseudohash?


Comment on RE: My views on pseudohashes
RE: RE: My views on pseudohashes
by Zoogie (Curate) on Jun 24, 2000 at 00:03 UTC
    I had no clue what a pseudohash was... until I started searching for "pseudo-hash" instead of "pseudohash". Apparently, you can use an array as a hash. Here's a a snippet from perlref on the subject:

    Beginning with release 5.005 of Perl you can use an array reference in some contexts that would normally require a hash reference. This allows you to access array elements using symbolic names, as if they were fields in a structure.

    For this to work, the array must contain extra information. The first element of the array has to be a hash reference that maps field names to array indices. Here is an example:

    $struct = [{foo => 1, bar => 2}, "FOO", "BAR"]; $struct->{foo}; # same as $struct->[1], i.e. "FOO" $struct->{bar}; # same as $struct->[2], i.e. "BAR" keys %$struct; # will return ("foo", "bar") in some order values %$struct; # will return ("FOO", "BAR") in same some order while (my($k,$v) = each %$struct) { print "$k => $v\n"; }

    - Zoogie

      That's pretty cool. I wonder what it's good for.
        This is just a guess (perhaps somebody who's more experienced with Perl compiler optimizations can help out here). Since accessing array elements tends to be faster than accessing hash elements, if the Perl compiler resolves the pseudo-hash keys to the array indexes at compile-time, it makes building structures with named elements more efficient at run-time than simply using hashes.

        The perlref page notes that the compiler does something to this effect for using named fields in objects. I'm not at all familiar with objects in Perl, so I can't really elaborate on that.

        - Zoogie

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://19642]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-08-20 11:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (111 votes), past polls