Hello DARK_SCIENTIST and welcome to the monastery.

Give Hash::Ordered a try. There is also MCE::Shared::Ordhash which can be constructed as a non-shared object. The two implementations are reasonably fast. The OO interface is faster whenever performance is desired.

use Hash::Ordered; use MCE::Shared::Ordhash; tie my %h1, 'Hash::Ordered', @pairs; tie my %h2, 'MCE::Shared::Ordhash', @pairs; my $h3 = Hash::Ordered->new( @pairs ); my $h4 = MCE::Shared::Ordhash->new( @pairs );

MCE::Shared::Ordhash supports OO and hash-like dereferencing at the same time. It's quite nice having OO for maximum performance and dereferencing when needed.

my $oh = MCE::Shared::Ordhash->new(); $oh->set( hello => "there" ); $oh->{hello} = "there"; # on-demand hash-like dereferencing $oh->assign( @pairs );

Examples.

use Hash::Ordered; tie my %h1, 'Hash::Ordered', qw( title1 foo title2 bar title3 baz ); my @labels1 = keys %h1; my $h2 = Hash::Ordered->new(qw( title1 foo title2 bar title3 baz )); my @labels2 = $h2->keys;

Both Hash::Ordered and MCE::Shared::Ordhash are light on memory consumption.

Regards, Mario.


In reply to Re: Transferring hash keys to array... Need help sorting by marioroy
in thread Transferring hash keys to array... Need help sorting by DARK SCIENTIST

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.