in reply to Fun with arrays and hashes
1. Is it possible to write an array to disk in the same way as you can a hash, with either the dbmopen/dbmclose or that tiehash thing?You surely can. With what I don't know as I'm unfamiliar with dbmopen() and dbmclose() (which are deprecated incidentally), but it's definitely possible.
2. How can I sequentially step through elements in a hash? For example with an array I would just 'push' things on, then I 'shift' them off.You can't as hashes are inherently unordered.
3. If I don't know the key from my hash, how can I just retrieve the first value?Since hashes aren't ordered you can't retrieve the first value. You could always sort() on the keys() in the hash which you could then iterate through in the resulting order.
For more info on hashes and arrays check out the official manpage on perl's data types, or pick up a copy of Learning Perl.
HTH
broquaint
|
|---|