Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Fun with arrays and hashes

by moodster (Hermit)
on Apr 16, 2002 at 15:23 UTC ( [id://159524]=note: print w/replies, xml ) Need Help??


in reply to Fun with arrays and hashes

1. I haven't meddled with dbmopen or tiehash, but you could always check out the Tie::Array module. Or go with Storable, which is included in the standard distribution and will store anything.

2 & 3. A hash is not ordered, so there is no way to access the 'first' element. However, the keys( %hash ) function returns an array of the keys of a hash. This array is not ordered and calling keys repeatedly may or may not yield the same results. A common construct is to sort the keys before looping over the array; this will step through the hash in the alpabetical order of the keys, which is nearly but not really the same thing you are asking for in 2)

for my $key ( sort keys %myhash ) { print "$key: $myhash($key)\n"; }

Cheers,
--Moodster

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found