LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Perl thing of the day

[ILUG] Perl thing of the day

Fergal Daly fergal at esatclear.ie
Wed Oct 17 12:47:46 IST 2001


I'm sure this exact piece of Perl has been written thousands of times by a
other people but I wrote it today and I think it's lovely

perl -pe 's/.*?(\d+)(.*)/"$2 ".("*" x $1)/ge'

will draw a histogram. It takes lines of the form

123 thing

and produces lines of the form

thing **********

where there are 123 *s

Got a list of usernames that have logged in over the last week?

sort list | uniq -c | perl -pe 's/.*?(\d+)(.*)/"$2 ".("*" x $1)/ge'

will graph them.

I had a bunch of account numbers generated by some unknown algorithm and I
wanted to know would it be good idea to to use the last 2 characters as a
hash. So I grabbed out the last two chars of each one and luckily enough

sort last_two | uniq -c | cut -f 1 | sort | uniq -c | perl -pe 's/.*?(\d+)(.*)/"$2 ".("*" x $1)/ge'

gave me a nice tight bell curve.

I love Perl :-)

Fergal





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell