Hi monks,
I'm looking someone to optimize my code
input file
picturesque liar fight nor fly 24 hours love life wrinkled a million dollars love life even plan you attempt things a million dollars many hardships many hardships married head many hardships this year secret shame present apple pie many hardships elephant careful peace many hardships apple pie good afternoon seven levels
Output is, we should count the items and which items coming more times in the input. I need to print most coming items of 5. Means, output for this input is
many hardships love life apple pie a million dollars this year
I have written a script, but its taking some time to finish this task.
#!/usr/bin/perl open(INP, '<', $ARGV[0]); while ($item=<INP>) { chomp($item); (exists $query{$item}) ? ($query{$item}=$query{$item}+1) : ($query +{$item}=1); } print join("\n", (sort {$query{$b}<=>$query{$a}} (keys %query))[0..4]) +."\n";
Basically i want to know, how to optimize this code as ninja speed
In reply to Speed up my code by arivu198314
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |