5.6. Retrieving from a Hash in Insertion OrderProblem
The Solutionuse Tie::IxHash; tie %HASH, "Tie::IxHash"; # manipulate %HASH @keys = keys %HASH; # @keys is in insertion order Discussion
Tie::IxHash makes
Tie::IxHash also provides an object-oriented interface to
Here's an example, showing both # initialize use Tie::IxHash; tie %food_color, "Tie::IxHash"; $food_color{Banana} = "Yellow"; $food_color{Apple} = "Green"; $food_color{Lemon} = "Yellow"; print "In insertion order, the foods are:\n"; foreach $food (keys %food_color) { print " $food\n"; } print "Still in insertion order, the foods' colors are:\n"; while (( $food, $color ) = each %food_color ) { print "$food is colored $color.\n"; } See AlsoThe documentation for the CPAN module Tie::IxHash; Recipe 13.15 Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|