Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: Golf: Count unique words

by Fletch (Chancellor)
on Nov 30, 2004 at 15:24 UTC ( #411209=note: print w/replies, xml ) Need Help??

in reply to Re: Golf: Count unique words
in thread Golf: Count unique words

73 (70 + 3 for the switches). The \b's are pretty much unnecessary and using $& means you don't need parens.

#!/usr/bin/perl -nl END{print map("$_ ($w{$_})\n",sort keys%w),$t}s/\w+/$w{$&}++;$t++/eg;

Replies are listed 'Best First'.
Re^3: Golf: Count unique words
by eyepopslikeamosquito (Chancellor) on Dec 01, 2004 at 06:36 UTC

    Sh?aving seven strokes:

    #!/usr/bin/perl -lp ++$t,++$w{$_}for/\w+/g}for(map("$_ ($w{$_})",sort keys%w),$t){

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://411209]
LanX wants to be fired
[Discipulus]: i fear no
[Discipulus]: i invented also 'gired'
[Lady_Aleena]: Discipulus, then that is a problem. I wanted to find total seconds of my entire .mp3 collection to do some math on it to see how many days of continuous music i have.
[LanX]: darn. .. I wanted to see Marine and Melonchon go to next round, just for fun xD
[Discipulus]: LA use Perl: traversing a dir tree is simple; foreach file mp3 $sec+= use Mp3::Info
[Lady_Aleena]: Discipulus, I was able to get the sum of the seconds on the command line using awk. Then I ran the result through a perl script and got the result. It came bach with 4 days, 9 hours, 56 minutes, 43 seconds.
[Lady_Aleena]: s/bach/back/;
[Discipulus]: gired anyway is the intermediate state between hired and fired (and vice versa;)
[Lady_Aleena]: Discipuluis, I don't know if I want to fight with File::Find. File::Find and I are not friends.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2017-04-23 20:32 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.