Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I'm pretty new to perl (hmm, maybe the obfuscated section isn't the best place for beginners...) and really love the regexs and the fact so little code can do so much. So I was particularly impressed when my first attempt at a small but nearly useful program worked (esp for Bram Stokers Dracula in 1.6 seconds):
s/\b(\w+)\b/$w{$1}++;$t++;$1;/eg while (<>); print "$_ ($w{$_})\n" for (sort keys %w); print "\n$t\n";
Having seen how fast it works, and how small it is, I started wondering if it could be made any smaller. Not necessarily obfuscated, but just compacted a bit.
So, can it?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Golf: Count unique words
by dragonchild (Archbishop) on Nov 30, 2004 at 15:02 UTC | |
by Fletch (Bishop) on Nov 30, 2004 at 15:24 UTC | |
by eyepopslikeamosquito (Archbishop) on Dec 01, 2004 at 06:36 UTC | |
Re: Golf: Count unique words
by Fletch (Bishop) on Nov 30, 2004 at 14:58 UTC | |
by dragonchild (Archbishop) on Nov 30, 2004 at 15:04 UTC | |
Re: Golf: Count unique words
by pearl (Initiate) on Nov 30, 2004 at 15:07 UTC | |
Re: Golf: Count unique words
by !1 (Hermit) on Nov 30, 2004 at 20:40 UTC | |
by Anonymous Monk on Dec 07, 2004 at 13:10 UTC | |
by Anonymous Monk on Dec 07, 2004 at 13:13 UTC |