# you can get rid of the ($netHash{$val} > 1.0) test
# I only included it to make the example more like yours
if($netHash{$val} > 1.0 && $netHash{$val} < 1.4) {
my ($x1, $y1) = ($val,$netHash{$val});
$capVal_1_Hash{$x1} = $y1;
}
elsif($netHash{$val} > 1.4 && $netHash{$val} < 1.9) {
my ($x2, $y2) = ($val,$netHash{$val});
$capVal_2_Hash{$x2} = $y2;
}
...
...
####
sub printHash {
my $href = shift;
my @href_keys = keys %{$href};
my $RandKey = $href_keys[int(rand(scalar @href_keys))];
print "$RandKey $href->{$RandKey}\n";
}
####
foreach my $n ( 1 .. 100 ) {
printHash( $capVal_hash{$n} );
}
####
my @range_destination
= ( [ 1.0, 1.4, 1 ],
[ 1.4, 1.9, 2 ],
...
[ 99.2, 99.8, 99 ],
[100.1, 100.9, 100 ],
);
# what you call $val is really a KEY,
# but I'll keep your name anyway.
while ( my ( $val, $real_val ) = each %netHash ) {
CONDITION:
foreach my $cond_ref ( @range_destination ) {
my ( $min, $max, $dest ) = @$cond_ref;
if ( $val > $min && $val < $max ) {
$capVal_Hash{$dest}{$val} = $real_val;
last CONDITION;
}
}
}