in reply to Maintainance of element order in hash

FAQ: How can I always keep my hash sorted?
  • Comment on Re: Maintainance of element order in hash

Replies are listed 'Best First'.
Re^2: Maintainance of element order in hash
by ravi45722 (Pilgrim) on Sep 29, 2016 at 13:03 UTC

    In seen  Tie::IxHash but in this I am seeing only key pair value. But I dont understand how to give nested hashes into it. Can you write a small snipplet for the above example using Tie::Ixhash

      I dont understand how to give nested hashes into it
      #!/usr/bin/env perl # Hash order maintained use strict; use warnings; use Test::More tests => 1; use Tie::IxHash; tie my %foo, 'Tie::IxHash'; $foo{a} = [3, 2, 1]; $foo{b} = { s => 'senatus', p => 'populus', q => 'que', r => 'romanus' + }; is_deeply ([keys %foo], [qw/a b/], 'Order retained');

      and see perldsc for how to use nested data structures generally.

        Thanks for reply. I tried this by using your example. But when I dumping the hash it is not in the ordered as we inserted. Where I am missing the logic???

        #!/usr/bin/env perl # Hash order maintained use strict; use warnings; use Test::More tests => 1; use Tie::IxHash; use Data::Dumper; tie my %foo, 'Tie::IxHash'; $foo{a}{c} = [3, 2, 1]; $foo{a}{b}{x} = { s => 'senatus', p => 'populus', q => 'que', r => 'ro +manus'}; $foo{a}{b}{y} = "ravi"; print Dumper \%foo;