in reply to Sort hash with values
Hash lookups typically involve searching keys for values, so your logic is backwards. Rearranging the hash order and changing values to keys gives something closer to what you probably want.
Update: The mySort routine looks like it's not doing it's job properly or efficiently. If you explain how you want the output sorted, I'm sure someone will have good advice.sub mySort { $a =~ /(\d+)/; my $firstVal = $1; $b =~ /(\d+)/; my $secVal = $1; $firstVal <=> $secVal; } my %IP_Store = ( "UEH1_system_ip" => "11.0.0.1", "UEH11_system_ip" => "11.0.0.11", "UEH25_system_ip" => "11.0.0.3", "UEH111_system_ip" => "11.0.0.25" ); foreach my $key (sort mySort (keys (%IP_Store))) { print "$key\n"; print "System_ip = '$IP_Store{$key}' \n"; }
In Section
Seekers of Perl Wisdom