Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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 ?

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 surveying the Monastery: (5)
As of 2020-09-24 12:34 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (133 votes). Check out past polls.