sort hash by values desc


I have a perl file to which i am feeding values of form

The perl file i am using is

use warnings;
use strict;

my( %count,%count1) = ();
my @words;
my ($filename,$args,$word,$str,$temp) = " ";

$args         = scalar(@ARGV);

if($args >= 1)
   $filename       = $ARGV[0];
   open INFILE, "< $filename" or die "Can not open $filename : $!";
}else {  die "Error: Incorrect number of arguments \n"; }

sub hashValueAscendingNum {
   $count{$b} <=> $count{$a};

  my @word = split (/:/,$_);
  foreach $word(@word)
    $count{$word[0]}++ if $word[0] =~ /^[http|https|ftp]/;
    $count1{$2}++ if $word[1] =~ /([^:]*:\/\/)?([^\/]+\.[^\/]+)/g;

foreach $str (sort hashValueAscendingNum (keys(%count)))
  printf " %30s %s \n", $str, $count{$str};

foreach $str (sort hashValueAscendingNum (keys(%count1)))
  printf " %30s %s \n", $str, $count1{$str};

However, i am not able to sort the %count1 by values desc ? ( Getting an error and hash is not sorted properly )

Also from %count and %count1, i want to display only 2 topmost records, which is not achieved via foreach loop

please advise ...
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

foreach $str ((sort { $count1{$b} <=> $count1{$a}} keys %count1)[0..1])
  printf " %30s %s \n", $str, $count1{$str};

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
clock_crazyAuthor Commented:
Thank you that works. I was missing the name of hash and while reviving values of hash, it always return in list.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.