Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Favourite modules April 2003 (scripted top10 list)

by Aristotle (Chancellor)
on Apr 16, 2003 at 00:43 UTC ( [id://250746]=note: print w/replies, xml ) Need Help??


in reply to Re: Favourite modules April 2003
in thread Favourite modules April 2003

You can certainly do alot better than that long piece of code for this task though. The last two loops can be combined:
for (sort { $module{$a} <=> $module{$b} } keys %module) { printf "%04d, %s\n", $module{$_}, $_; }
Gets you rid of the synthetic @list too. I have no idea what your if/elsif are supposed to sort out, either. And finally, instead of using <DATA>, you can use <> and just pipe the output from grep to the script. A compressed version:
/^use\s+([^\s;]+)/ && $_{$1}++ while <>; printf "%04d, $_\n", $_{$_} for sort { $_{$b} <=> $_{$a} } keys %_;
And then it's just
$ grep -hr ^use perl/ | perl foo.pl

Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://250746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-03-28 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found