Assuming you mean in the order they were saved in the hash, the module
Tie::IxHash provides such access. It should have sufficient examples, but i'll briefly describe what it does...
When you tell perl to bind a normal hash interface with what's called a tied object, in this case a Tie::IxHash tied object, the object takes care of the internals. The Tie::IxHash module provides internal structures which contain regular hashes and arrays, containing additional data to determine the order, not only the value. The interface is the same, but allowes different functionality.
When you've tied your hash to a Tie::IxHash you may then
delete(@hash{(keys)[0 .. 2]}). That approach, though functional, is good for 10 elements but not many more. You should probably delete iteratively, using
each.
Update: Changed IxHash to Tie::IxHash, squashed a typo.
-nuffin
zz zZ Z Z #!perl
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.