Here's a quick way: perl -e '$var="abdaatela"; print ((scalar grep /a/,(split /(.)/,$var)),"\n");'
grep returns the number of matches in a scalar context, and the split breaks the string up into separate elements. The parens in the split return the item split on (otherwise it would throw away each character it encountered). Paul PS. Wow, it almost looks like I know what I'm talking 'bout, don't it? 8-) Yesterday, Juerg Oehler wrote: > hi, > > how do efficent count char 'a' in string "abdaatela" ? > > i guess there are better solutions than: > > $tmpstr =~ s/[^a]//g ; > $cnt = length ($tmpstr) ; > print ("found <$cnt> a's <$tmpstr>\n"); > > thanx > george > > > > -------------------------------------------------------------------- "My parents just came back from a planet where the dominant lifeform had no bilateral symmetry, and all I got was this stupid F-Shirt." -------------------------------------------------------------------- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]