Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

RE: My views on pseudohashes

by csorensen (Beadle)
on Jun 28, 2000 at 02:18 UTC ( #20093=note: print w/ replies, xml ) Need Help??


in reply to RE: My views on pseudohashes
in thread My views on pseudohashes

am I missing something .. aren't pseudo-hashes and anonymous arrays the same thing ?


Comment on RE: My views on pseudohashes
RE: RE: My views on pseudohashes
by extremely (Priest) on Jun 29, 2000 at 18:57 UTC
    No they aren't. An anonymous array is an array without a formal name. Like:
    my $q = [ $a, $b, $c, $d];
    returns an anonymous array ref into $q, you created an array without ever declaring an named array like with `my'.

    A pseudo-hash is an array (anonymous or not) that has a special first entry. Pseudo-hashes are still listed in `perldoc perlref' as experimental. try this:

    my @ph; $ph[0]={Foo=>1, Bar=>2, Bag=>3}; $ph[1]="what Foo points to"; $ph[2]="what Bar points to"; $ph[3]="what Bag points to"; print "$ph{Foo} is $ph[1]\n";

    In effect making the first item in an array a hash where each key points to a row index lets you use the array like a hash. All you favorite hash tricks work, `keys', `values', `exists' and more. The real win here is that you have an intrisic order to the hash thanks to the array, but the hash tools won't naturally return in that order, you have to do it yourself. Also, you can't add a new field with a simple `$ph{New}="a new item"' cause it doesn't know how to do it.

    If you decide to play with em, PLEASE read the `perldoc perlref' section on it. There are some handy-dandy tools in perl 5.6 like `perldoc fields' that will add some compile time sanity and ease of use to them.

    HTH somebody. =)

    -- mark

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2014-07-26 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls