Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Golf: Count unique words

by !1 (Hermit)
on Nov 30, 2004 at 20:40 UTC ( #411269=note: print w/replies, xml ) Need Help??


in reply to Golf: Count unique words

Just throwing this one out there for fun and to show a different approach:

#!/usr/bin/perl -nla INIT{undef$/};$w{$_}++for@F;print"$_ ($w{$_})"for keys%w;print"".@F # 345678 1 2345678 2 2345678 3 2345678 4 2345678 5 2345678 6 234567

67 + 4 = 71 strokes

Replies are listed 'Best First'.
Re^2: Golf: Count unique words
by Anonymous Monk on Dec 07, 2004 at 13:10 UTC
    #!/usr/bin/perl -0nla $w{$_}++for@F;print"$_ ($w{$_}) "for keys%w;print~~@F small correction :)
      #!/usr/bin/perl -0na
      $w{$_}++for@F;print"$_ ($w{$_})
      "for keys%w;print~~@F

      there is literal \n at the end of second line

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2021-08-05 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?