in reply to Data::Sorting
It will automatically keep the hash sorted even if you add/delete keys or modify the key's value to a new anonymous hash. You will have to read TFM carefully if those array refs are not anonymous as some other code may modify their values behind the scense (which requires modifying the optimization type). If you want more info let me know - I am late for a meeting.#!/usr/bin/perl use strict; use warnings; use Tie::Hash::Sorted; my $sort = sub { my $h = shift; [ sort { $h->{$a}[0] cmp $h->{$b}[0] || $h->{$a}[1] cmp $h->{$b}[1] || $h->{$a}[2] cmp $h->{$b}[2] } keys %$h ]; }; tie my %s_hash, 'Tie::Hash::Sorted', 'Sort_Routine' => $sort, 'Optimiz +ation' => 'values'; %s_hash = ( 1 => [ qw(Frog Fuzzy A other_stuff) ], 2 => [ 'Frog', 'Fuzzy', '', 'other_stuff' ], 3 => [ qw(Toad Zola Q other_stuff) ], 4 => [ qw(Frogger Anthony J other_stuff) ], 5 => [ qw(Frog-Toad Berl G other_stuff) ], ); print "$_\n" for keys %s_hash;
Cheers - L~R
|
|---|