[26966] in Perl-Users-Digest
Perl-Users Digest, Issue: 8919 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 4 14:05:58 2006
Date: Sat, 4 Feb 2006 11:05:03 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 4 Feb 2006 Volume: 10 Number: 8919
Today's topics:
Match on x instances of a character <mordred_au@hotmail.com>
Re: Match on x instances of a character <no@email.com>
Re: Match on x instances of a character (Anno Siegel)
Re: Match on x instances of a character <mordred_au@hotmail.com>
Re: Match on x instances of a character <mordred_au@hotmail.com>
Re: Match on x instances of a character <uri@stemsystems.com>
Re: Obscure utf8/"panic: malloc" bug <socyl@987jk.com.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 04 Feb 2006 20:31:55 +1030
From: John Burgess <mordred_au@hotmail.com>
Subject: Match on x instances of a character
Message-Id: <43e47b48$1@dnews.tpgi.com.au>
Hi,
I am having some trouble with regexps and hope someone can help.
Problem: Iterating through a list of newsgroups and matching only those
with 2 .'s in the name. So comp.lang.perl would match but comp.lang or
comp.lang.perl.misc would not.
(Broken) Solution: I have got something like this
$test = "comp.lang.perl";
if ($test =~ m/([^\.]\.[^\.]){2}/g) {print STDERR "$test is 2\n";} else
{print STDERR "$test is not 2\n";}
Clearly this doesn't work. I can't see what I'm doing wrong. Tips
appreciated.
John
------------------------------
Date: Sat, 04 Feb 2006 11:03:47 +0000
From: Brian Wakem <no@email.com>
Subject: Re: Match on x instances of a character
Message-Id: <44jg0jF248hkU1@individual.net>
John Burgess wrote:
> Hi,
> I am having some trouble with regexps and hope someone can help.
>
> Problem: Iterating through a list of newsgroups and matching only those
> with 2 .'s in the name. So comp.lang.perl would match but comp.lang or
> comp.lang.perl.misc would not.
>
> (Broken) Solution: I have got something like this
>
> $test = "comp.lang.perl";
> if ($test =~ m/([^\.]\.[^\.]){2}/g) {print STDERR "$test is 2\n";} else
> {print STDERR "$test is not 2\n";}
>
> Clearly this doesn't work. I can't see what I'm doing wrong. Tips
> appreciated.
>
> John
#!/usr/bin/perl
use strict;
use warnings;
while(<DATA>){
chomp;
my $dots = tr/.//;
print "$_ has $dots dots\n";
}
__DATA__
comp.lang
comp.lang.perl
comp.lang.perl.misc
###########
$ perl scripts/tmp/tmp72.pl
comp.lang has 1 dots
comp.lang.perl has 2 dots
comp.lang.perl.misc has 3 dots
See perldoc -q count
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: 4 Feb 2006 11:32:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Match on x instances of a character
Message-Id: <ds23c2$fsk$1@mamenchi.zrz.TU-Berlin.DE>
John Burgess <mordred_au@hotmail.com> wrote in comp.lang.perl.misc:
> Hi,
> I am having some trouble with regexps and hope someone can help.
>
> Problem: Iterating through a list of newsgroups and matching only those
> with 2 .'s in the name. So comp.lang.perl would match but comp.lang or
> comp.lang.perl.misc would not.
>
> (Broken) Solution: I have got something like this
>
> $test = "comp.lang.perl";
> if ($test =~ m/([^\.]\.[^\.]){2}/g) {print STDERR "$test is 2\n";} else
What is the /g for? It makes no sense, you're not looking for multiple
occurences of anything. Further, in a character class a dot is not
special, so the "\" is not needed. Third, you forgot an asterisk after
each character class that matches non-dots, so it can never match more
than one non-dot in a row. Fourth, you are using capturing parentheses
for grouping. Fifth, you didn't anchor your match to the beginning and
the end of the string, so, even with the other corrections it would match
anything with two or more dots in it.
> {print STDERR "$test is not 2\n";}
Applying all of this to your regex, it becomes
/^(?:[^.]*\.[^.]*){2}$/
which dies indeed match what you want.
However, the easiest (and fastest) way of counting characters is the
tr/// operator:
if ( tr/.// == 2 ) { #...
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Sat, 04 Feb 2006 23:02:28 +1030
From: John Burgess <mordred_au@hotmail.com>
Subject: Re: Match on x instances of a character
Message-Id: <43e49e8f$1@dnews.tpgi.com.au>
Thanks Brian, I was aware the tr function would do it. However I was
planning to use the match in a grep and so I dont think the tr is so
economical. I am also testing these options for speed and thats part of
the reason for finding the match function. To see which is fastest.
Thanks very much for your input though!
Regards,
John
Brian Wakem wrote:
> John Burgess wrote:
>
>
>>Hi,
>> I am having some trouble with regexps and hope someone can help.
>>
>>Problem: Iterating through a list of newsgroups and matching only those
>>with 2 .'s in the name. So comp.lang.perl would match but comp.lang or
>>comp.lang.perl.misc would not.
>>
>>(Broken) Solution: I have got something like this
>>
>>$test = "comp.lang.perl";
>>if ($test =~ m/([^\.]\.[^\.]){2}/g) {print STDERR "$test is 2\n";} else
>>{print STDERR "$test is not 2\n";}
>>
>>Clearly this doesn't work. I can't see what I'm doing wrong. Tips
>>appreciated.
>>
>>John
>
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> while(<DATA>){
> chomp;
> my $dots = tr/.//;
> print "$_ has $dots dots\n";
> }
>
>
> __DATA__
> comp.lang
> comp.lang.perl
> comp.lang.perl.misc
>
> ###########
>
> $ perl scripts/tmp/tmp72.pl
> comp.lang has 1 dots
> comp.lang.perl has 2 dots
> comp.lang.perl.misc has 3 dots
>
>
> See perldoc -q count
>
>
------------------------------
Date: Sat, 04 Feb 2006 23:27:09 +1030
From: John Burgess <mordred_au@hotmail.com>
Subject: Re: Match on x instances of a character
Message-Id: <43e4a458$1@dnews.tpgi.com.au>
Seems I really was off the track a bit. I am no regexp pro. I'm trying
though. Your example does indeed work. Your comment about speed is
interesting. Part of the reason for finding the correct match regexp was
to test for speed, which I will still test. The other thing is I want to
use this in a grep and I'm not sure the tr can be used economically in
this context? Thanks for your help. I'll be sure and go over where you
say I've got it wrong. Your comments make a lot of sense.
Regards,
John
Anno Siegel wrote:
> John Burgess <mordred_au@hotmail.com> wrote in comp.lang.perl.misc:
>
>>Hi,
>> I am having some trouble with regexps and hope someone can help.
>>
>>Problem: Iterating through a list of newsgroups and matching only those
>>with 2 .'s in the name. So comp.lang.perl would match but comp.lang or
>>comp.lang.perl.misc would not.
>>
>>(Broken) Solution: I have got something like this
>>
>>$test = "comp.lang.perl";
>>if ($test =~ m/([^\.]\.[^\.]){2}/g) {print STDERR "$test is 2\n";} else
>
>
> What is the /g for? It makes no sense, you're not looking for multiple
> occurences of anything. Further, in a character class a dot is not
> special, so the "\" is not needed. Third, you forgot an asterisk after
> each character class that matches non-dots, so it can never match more
> than one non-dot in a row. Fourth, you are using capturing parentheses
> for grouping. Fifth, you didn't anchor your match to the beginning and
> the end of the string, so, even with the other corrections it would match
> anything with two or more dots in it.
>
>
>>{print STDERR "$test is not 2\n";}
>
>
> Applying all of this to your regex, it becomes
>
> /^(?:[^.]*\.[^.]*){2}$/
>
> which dies indeed match what you want.
>
> However, the easiest (and fastest) way of counting characters is the
> tr/// operator:
>
> if ( tr/.// == 2 ) { #...
>
> Anno
------------------------------
Date: Sat, 04 Feb 2006 14:02:22 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Match on x instances of a character
Message-Id: <x7u0bfne0x.fsf@mail.sysarch.com>
>>>>> "JB" == John Burgess <mordred_au@hotmail.com> writes:
JB> Seems I really was off the track a bit. I am no regexp pro. I'm
JB> trying though. Your example does indeed work. Your comment about
JB> speed is interesting. Part of the reason for finding the correct
JB> match regexp was to test for speed, which I will still test. The
JB> other thing is I want to use this in a grep and I'm not sure the
JB> tr can be used economically in this context? Thanks for your
JB> help. I'll be sure and go over where you say I've got it
JB> wrong. Your comments make a lot of sense.
please stop top posting. read the frequently posted group guidelines for
more about that.
what does 'used economically in this context' mean? what context? why
are you so speed conscious about this? have you found it to be a major
bottleneck and you need more speed? and tr/// isn't a regex so don't
confuse it with them. and tr/// *IS* the fastest way to count chars in a
string. there is no way a regex can beat it for something as simple as
that. tr/// is designed for character oriented operations.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sat, 4 Feb 2006 17:55:59 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Re: Obscure utf8/"panic: malloc" bug
Message-Id: <ds2prf$le5$1@reader2.panix.com>
In <ds0t4r$q5m$1@agate.berkeley.edu> Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:
>[A complimentary Cc of this posting was sent to
>kj
><socyl@987jk.com.invalid>], who wrote in article <ds02fu$jl2$1@reader2.panix.com>:
>>
>> I'm trying to find a workaround to bug that is causing me a lot of
>> problems now. This bug surfaces under very rare conditions, but
>> they happen to apply to me at the moment.
>>
>> I've traced the bug to the execution of line 49 of DBD/mysql.pm
>> (v. 3.0002) (though I'm almost certain that the involvement of
>> DBD/mysql.pm here is purely coincidental):
>>
>> if ($dsn =~ /([^:;]*)[:;](.*)/) {
>>
>> At the time of failure, the $dsn variable contains, as far as I
>> can tell, the string "host=martdb.ebi.ac.uk;port=3306". If, within
>> the Perl debugger, I turn on tracing when the program reaches the
>> line shown above, but right before failure, I see that (somehow),
>> the code being executed is from the function SWASHNEW in
>> /usr/lib/perl5/5.8.6/utf8_heavy.pl.
>With the current state of Perl internals (non-reenterable REx engine),
>debugging into SWASH* functions can only lead to a disaster
Thanks for this insight. As it turns out, this bug surfaces *only*
when I run the code in the debugger which means that I cannot debug
this code using the Perl debugger; this I consider a significant
hindrance. If I understand what you say correctly, this situation
means that any Perl code that (directly or indirectly) invokes
SWASHNEW cannot be debugged using the Perl debugger.
Honestly, I can't understand why utf8 and utf8_heavy are being
loaded at all. I painstakingly traced the moment at which utf8
first appears in %INC to the following line:
/usr/lib/perl5/vendor_perl/5.8.6/i586-linux-thread-multi/DBI.pm:555:
555: $dsn =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i
556: or '' =~ /()/; # ensure $1 etc are empty if matc
...but I don't see why this code causes utf8.pm to be loaded at all!
(FWIW, when this all happens the string in $dsn does not contain
anything other than ASCII characters.) The loading of utf8_heavy.pl
happens under equally mysterious circumstances. It's like voodoo...
Is there a way to "go up the call stack" in the debugger (to examine
lexical values in the calling environment)?
Also, is there a way to generate a call tree for a Perl program?
>(although
>I did not know this may be malloc()-related).
In retrospect, I think my mention of malloc was probably premature.
It is true that, in *some* runs (this is somewhat of a heisenbug),
the value of $@ after I run the whole thing within an eval does
say something like "panic: malloc at line /path/to/DBD/mysql.pm
line 49", but it could be that the malloc error is downstream of
the real error.
>I wrote about this here
>about a year ago.
I didn't have much luck when I searched clpm with Google Groups
for your earlier posts on this, but maybe I didn't use the right
search keywords. Can you help me narrow down the search?
Thanks again,
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8919
***************************************