Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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
Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2015-10-09 23:08 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (253 votes), past polls