in reply to sorting hashes
On the other hand, sometimes that is exactly what you want which is why I wrote Tie::Hash::Sorted.
Remember, anytime you use a tied implementation there is going to be a performance penalty. I have taken quite a few steps to optimize this module so if it is something you are interested, be sure to read the docs on how to get the most out of it. If you have any questions, please let me know.#!/usr/bin/perl use strict; use warnings; use Tie::Hash::Sorted; my $numerically = sub { my $hash = shift; [ sort { $a <=> $b } keys %$hash ]; }; tie my %hash, 'Tie::Hash::Sorted', 'Sort_Routine' => $numerically; %hash = map { $_ => undef } 1..25; for ( keys %hash ) { tie %{ $hash{ $_ } }, 'Tie::Hash::Sorted', 'Sort_Routine' => $nume +rically; %{ $hash{ $_ } } = map { (int rand 5000) => undef } 1..5; for my $key ( keys %{ $hash{ $_ } } ) { @{ $hash{ $_ }{ $key } }{ qw/first last min max/ } = map { int +(rand 100) + 1 } 1..4; } } # Modify %hash however you want and don't worry about it for my $o_key ( keys %hash ) { for my $i_key ( keys %{ $hash{ $o_key } } ) { print "$o_key : $i_key\n"; # do something with $hash{ $o_key }{ $i_key } if you want } }
Cheers - L~R
|
|---|