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
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
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
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
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
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
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
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
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
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++;
10 matches
Mail list logo