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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |