From: "F. Senault" Date: 2009-02-11T07:08:57+09:00 Subject: Re: Counting Occurrences of a String in an Array Le 10 f�vrier 2009 � 22:51, shrouded.shoyu@gmail.com a �crit : > So, for example, my array is ["aaa", "aab", "abb", "bbb"] and I want > to return a new array that tells me how many times "a" appears: [3, 2, > 1, 0] When you need to map elements of an array to another array, the method to use is, no surprise here, map (a/k/a collect). Now, finding the number occurences of a string inside another one can be done in a few ways, depending on what you mean exactly. Scan is one : >> [ "aaa", "aab", "abb", "bbb" ].map { |x| x.scan(/a/).length } => [3, 2, 1, 0] Fred -- Perl already has _bless_, and we know what it does... [it] should also have _smite_, and we know what it should do, too. If more languages had _smite_ implemented, the remaining programmers would be better than the current average. (Mike Andrews in the SDM)