Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^2: String sorting in Perl

by Limbic~Region (Chancellor)
on Jun 04, 2014 at 17:38 UTC ( #1088695=note: print w/replies, xml ) Need Help??

in reply to Re: String sorting in Perl
in thread String sorting in Perl

And you're done.

It appears the OP is interested in getting the values out in descending order (sorted).

for my $line (sort {$count_hash{$b} <=> $count_hash{$a}} keys %count_h +ash) { print "$line $count_hash{$line}\n"; }

Cheers - L~R

Replies are listed 'Best First'.
Re^3: String sorting in Perl
by Laurent_R (Canon) on Jun 04, 2014 at 17:48 UTC
    Yes, Limbic~Region, you're right ++, that's why I updated the post immediately after I posted it, but you saw it before I posted the change. Having said that, my understanding on how the sort should be carried out is not exactly the same as yours (I explained it in my update).
      The code should get the counts, order them with the highest counts first, then move to the next value.

      I didn't see anything that implied shorter strings should come first but I agree that "move to the next value" is fairly ambiguous.

      Cheers - L~R

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1088695]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2018-02-20 20:02 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (274 votes). Check out past polls.