Re: fast match count of char in string

2003-07-18 Thread Steve Grazzini
On Fri, Jul 18, 2003 at 01:15:15PM -0500, Paul Archer wrote: > 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

Re: fast match count of char in string

2003-07-18 Thread Paul Archer
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

RE: fast match count of char in string

2003-07-17 Thread Charles K. Clarkson
Juerg Oehler [mailto:[EMAIL PROTECTED] wrote: : Sent: Thursday, July 17, 2003 11:09 AM : To: [EMAIL PROTECTED] : Subject: fast match count of char in string : : : hi, : : how do efficent count char 'a' in string "abdaatela" ? Plagiarizing from perlfaq4: "How

fast match count of char in string

2003-07-17 Thread Juerg Oehler
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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail