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

Re: match count

2003-07-11 Thread Jeff 'japhy' Pinyan
On Jul 7, David Storrs said: >> What the \K does is make the regex think it JUST started matching, so >> instead of replacing a bunch of stuff plus some extra fluff with the >> original bunch of stuff, we just say "after you've matched X, pretend you >> started matching HERE." It comes in handy i

Re: match count

2003-07-07 Thread David Storrs
On Sat, Jul 05, 2003 at 11:29:12AM -0400, Jeff 'japhy' Pinyan wrote: > On Jul 3, George P. said: > > >> while ($string =~ /pattern/g){ > >> $count++; > >> if ($count > $max_count){ > >> $string = substr($string,0,pos($string)); > >> last; > >> } > >> } > > > >$string =~ s/((.*?$patte

Re: match count

2003-07-05 Thread Jeff 'japhy' Pinyan
On Jul 3, George P. said: >> while ($string =~ /pattern/g){ >> $count++; >> if ($count > $max_count){ >> $string = substr($string,0,pos($string)); >> last; >> } >> } > >$string =~ s/((.*?$pattern){$max_count})(.*)/$1/s; You don't need to capture the .* at the end of the regex. This

Re: match count

2003-07-02 Thread George P.
On Wed, 2 Jul 2003, Ling F. Zhang wrote: > I use /pattern/g to progressively match a string (who > content is read from a file) > I want the cut the string off after the n-th match (if > there is no n-th match, the string is unaltered) > how can I do this without using a loop? > right now, I am

Re: match count

2003-07-02 Thread Casey West
It was Wednesday, July 02, 2003 when Ling F. Zhang took the soap box, saying: : I use /pattern/g to progressively match a string (who : content is read from a file) : I want the cut the string off after the n-th match (if : there is no n-th match, the string is unaltered) : how can I do this withou

match count

2003-07-02 Thread Ling F. Zhang
I use /pattern/g to progressively match a string (who content is read from a file) I want the cut the string off after the n-th match (if there is no n-th match, the string is unaltered) how can I do this without using a loop? right now, I am doing this: while ($string =~ /pattern/g){ $count++;