in reply to Re: Speed up my code
in thread Speed up my code

Much shorter :)

$ perl -ne'$x{$_}++}END{print"$x{$_}\t$_"for(sort{$x{$b}<=>$x{$a}}keys +%x)[0..4]' test.txt 5 many hardships 2 a million dollars 2 love life 2 apple pie 1 you attempt things

Enjoy, Have FUN! H.Merijn