in reply to Reference to hash tied with Tie::IxHash doesn't remember insertion order

What you want to do is not use a standard hash, but instead use the Tie::IxHash OO methodology. It's not as clean, but it'll do what you want.

#!/usr/local/bin/perl -w use strict; use Tie::IxHash; my $h = fooFunc(); print "This order now matches fooFunc()\n\n"; print $h->FETCH($_)."\n" for $h->Keys; print "\n"; sub fooFunc { my $h = Tie::IxHash->new('donald' => 'duck'); $h->Push('calvin' => 'human'); $h->Push('hobbes' => 'tiger'); $h->Push('mickey' => 'mouse'); $h->Push('zorak' => 'bug'); return $h; }

Review the perldoc for Tie::IxHash for more info.

  • Comment on Re: Reference to hash tied with Tie::IxHash doesn't remember insertion order
  • Download Code