[27078] in Perl-Users-Digest
Perl-Users Digest, Issue: 8972 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 19 11:05:46 2006
Date: Sun, 19 Feb 2006 08:05:04 -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 Sun, 19 Feb 2006 Volume: 10 Number: 8972
Today's topics:
[ANNOUNCE] Emacs modules for Perl programming (Jari Aalto+mail.perl)
Re: Need advice on debugging malloc bug (XML::Parser::E <pue@gmx.net>
Speeding up <gamo@telecable.es>
Re: Speeding up <no@email.com>
Re: Speeding up (Anno Siegel)
Re: Speeding up <gamo@telecable.es>
Re: Speeding up <1usa@llenroc.ude.invalid>
Re: Speeding up <abigail@abigail.nl>
Re: The inverse problem: generate all instances of a re (See Website For Email)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Feb 2006 05:45:05 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: [ANNOUNCE] Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1140327879@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
Maintainer: Jari Aalto A T cante net
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
and XEmacs port
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
http://math.berkeley.edu/~ilya/software/emacs/
by Ilya Zakharevich
CPerl is major mode for editing perl files. Also included in
latest Emacs, but newest version is at Ilya's site. Note that
the directrory at CPAN is out of date:
http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
Compared to default `perl-mode' that comes with Emacs, this
one has more features.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr@ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Sun, 19 Feb 2006 14:31:53 +0100
From: Andreas Puerzer <pue@gmx.net>
Subject: Re: Need advice on debugging malloc bug (XML::Parser::Expat)
Message-Id: <45raa9F7vc6gU1@individual.net>
kj schrieb:
[bug description kept for completeness]
> I have run out of things to try to fix a particular bug, and I'm
> hoping some of you may be able to give me some ideas.
>
> The bug happens only when the program is run inside the Perl debugger
> (which I do often; the Perl debugger is an integral part of my
> development environment).
>
> To reproduce the bug, the program must first invoke
> XML::Parser::Expat::ParseString to parse some XML. Once the parsing
> finishes, if I attempt to match a capture-containing regexp to a
> string obtained from the match, one of a few bad things happen:
> either the capture (e.g. $1) will contain garbage; or the program
> will die with a "panic: malloc" error; or the program will hang;
> or the program will die with an "Out of memory!" error.
>
> The following snippet illustrates the sequence I just described
> (but before you "try this at home", read below):
>
> use strict;
> use warnings;
> use XML::Parser::Expat;
>
> my $xml = '<?xml version="1.0"?><Foo></Foo>';
> my $content = '';
> my $parser = XML::Parser::Expat->new();
>
> $parser->setHandlers(Start => sub { $content .= ">@_<" });
>
> XML::Parser::Expat::ParseString($parser->{Parser}, $xml);
>
> print "$content\n"; # shows that the parsing happend
> $content =~ /([a-z]+)/; # BOOM!
> print "OK\n";
> __END__
>
> % perl -d expat_bug.pl
> ....
> main::(expat_bug.pl:6): my $xml = '<?xml version="1.0"?><Foo></Foo>';
> DB<1> r
>
>>XML::Parser::Expat=HASH(0x8342150) Foo<
>
> panic: malloc at expat_bug.pl line 15.
> at expat_bug.pl line 15
>
>
> Unfortunately, I have not been able to reproduce this bug anywhere
> outside our system (Linux SuSE). (In other words, if I don't fix
> this problem, probably no one will.)
Bug reproduced here on WindowsXP, AS Perl 5.8.4, Expat 2.34;
I could not reproduce it with Cygwin Perl 5.8.7, Expat 2.34!
Strangely, I don't get any of the different panic messages you describe, it just
segfaults silently every time I use the debugger on it. I still don't quite
understand why it segfaults with the AS Perl, but not with the Cygwin Perl. (Ok,
to be honest, I don't understand why it segfaults at all... ;->)
>
> I have re-built and re-installed perl, XML::Parser, and libexpat,
> and still the problem persists.
>
> I looks like the root of the bug is that some part of memory is
> being overwritten by mistake (a rather typical occurrence with C
> programs).
Just being curious, but how do you come to this conclusion?
>
> What tool would you recommend to catch something like this?
Normally I would recommend to use the debugger..., which unfortunately doesn't
seem to be helpful here, right?!
>
> Any other suggestions would be much appreciated.
Some Ideas:
The setup you showed used 5.8.6, my Cygwin, which seems unaffected, is 5.8.7,
maybe it's a known &, in newer versions at least, resolved issue? Have you
searched the bug-database? ( or already tried it with 5.8.7 or 5.8.8 to no avail?)
Another thing I noticed:
/([a-z]+)/ # original RE, segfaults
/[a-z]+/ # works fine!
/([\w]+)/ # segfaults
/(\w+)/ # works fine!
To me it seems like the Captures are only half the problem, the bug only shows
when there are also character classes used.
>
> kj
>
Andreas Pürzer
--
Have Fun,
and if you can't have fun,
have someone else's fun.
The Beautiful South
------------------------------
Date: Sun, 19 Feb 2006 08:38:45 +0100
From: gamo <gamo@telecable.es>
Subject: Speeding up
Message-Id: <Pine.LNX.4.64.0602190836490.27545@jvz.es>
I want to speed up this code:
$kk=0;
for (0..7){
$kk++ if (index($k,$res[$_]) >=0);
}
if ($kk==8){
...
TIA
--
http://www.telecable.es/personales/gamo/
------------------------------
Date: Sun, 19 Feb 2006 10:04:46 +0000
From: Brian Wakem <no@email.com>
Subject: Re: Speeding up
Message-Id: <45qu5uF7qddiU1@individual.net>
gamo wrote:
>
> I want to speed up this code:
>
> $kk=0;
> for (0..7){
> $kk++ if (index($k,$res[$_]) >=0);
> }
> if ($kk==8){
> ...
>
> TIA
>
You haven't told us what is in $k or @res. But in any case, index will
likely be the fastest way to do it.
Using != -1 instead of >=0 might buy you a millionth of a second.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: 19 Feb 2006 10:24:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Speeding up
Message-Id: <dt9h1q$p24$1@mamenchi.zrz.TU-Berlin.DE>
gamo <gamo@telecable.es> wrote in comp.lang.perl.misc:
>
> I want to speed up this code:
>
> $kk=0;
> for (0..7){
> $kk++ if (index($k,$res[$_]) >=0);
> }
> if ($kk==8){
> ...
Try (untested)
unless ( grep index( $k, $res[ $_]) < 0, 0 .. 7 ) {
Benchmark it. It is shorter, it may or may not be faster.
Anno
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: Sun, 19 Feb 2006 11:45:00 +0100
From: gamo <gamo@telecable.es>
Subject: Re: Speeding up
Message-Id: <Pine.LNX.4.64.0602191140120.285@jvz.es>
On Sun, 19 Feb 2006, Anno Siegel wrote:
> Try (untested)
>
> unless ( grep index( $k, $res[ $_]) < 0, 0 .. 7 ) {
>
> Benchmark it. It is shorter, it may or may not be faster.
>
> Anno
#!/usr/local/bin/perl -w
use Benchmark 'cmpthese';
$k = "11-12-13-14-15-16-17-18-";
@res = qw( 11 12 13 14 15 16 17 18);
cmpthese -5, {
'for' => sub {
$kk=0;
for (0..7){
$kk++ if (index($k,$res[$_]) >=0);
}
if ($kk==8){
;
}
},
'grep' => sub {
unless ( grep index( $k, $res[ $_]) < 0, 0 .. 7 ) {
;
}
},
};
__END__
Rate for grep
for 167564/s -- -36%
grep 261988/s 56% --
Thank you for the responses. The problem was more related with $k.
Doing
for $i (){
for $j (){
for $k (reverse @combinations){
code;
}
}
}
the thing was severely improved.
Thank you for your responses.
Cheers.
------------------------------
Date: Sun, 19 Feb 2006 10:48:25 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Speeding up
Message-Id: <Xns976F3B2B46E02asu1cornelledu@127.0.0.1>
gamo <gamo@telecable.es> wrote in news:Pine.LNX.4.64.0602190836490.27545
@jvz.es:
> I want to speed up this code:
>
> $kk=0;
> for (0..7){
> $kk++ if (index($k,$res[$_]) >=0);
> }
> if ($kk==8){
Have you measured where your program actually spends it time?
Well, here are some meaningless results:
#!/usr/bin/perl
use strict;
use warnings;
my $s = <<EO_TEXT;
gamo posted a question about making a meaningless piece of code
faster. He did not provide any sample data nor did he provide a
short but complete script others can run. It looks like gamo has
not read the posting guidelines. Please do.
EO_TEXT
my @r = qw( gamo post question provide FAQ short incomplete don't);
sub gamo_index {
my $kk = 0;
for (0 .. 7) {
$kk++ if 0 <= index $s, $r[$_];
}
}
sub gamo_grep { scalar grep { 0 <= index $s, $_ } @r }
use Benchmark qw( cmpthese );
cmpthese -1, {
gamo_index => \&gamo_index,
gamo_grep => \&gamo_grep,
};
__END__
D:\Home\asu1\UseNet\clpmisc\faster> f
Rate gamo_index gamo_grep
gamo_index 57389/s -- -34%
gamo_grep 86624/s 51% --
However, a meaningful optimization would look at the overall problem you
are trying to solve. Trying to make individual lines go faster is
generally meaningless.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 19 Feb 2006 12:39:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Speeding up
Message-Id: <slrndvgpnr.1fv.abigail@alexandra.abigail.nl>
gamo (gamo@telecable.es) wrote on MMMMDLV September MCMXCIII in
<URL:news:Pine.LNX.4.64.0602190836490.27545@jvz.es>:
:}
:} I want to speed up this code:
:}
:} $kk=0;
:} for (0..7){
:} $kk++ if (index($k,$res[$_]) >=0);
:} }
:} if ($kk==8){
:} ...
:}
:} TIA
The obvious improvement is to stop testing as soon as one test
fails, as you only want to do something if all cases match.
You'd have to benchmark with data that's relevant for your application
(and test both data that matches *and* data that fails).
One way of writing would be:
if (index ($k => $res [0]) >= 0 &&
index ($k => $res [1]) >= 0 &&
index ($k => $res [2]) >= 0 &&
index ($k => $res [3]) >= 0 &&
index ($k => $res [4]) >= 0 &&
index ($k => $res [5]) >= 0 &&
index ($k => $res [6]) >= 0 &&
index ($k => $res [7]) >= 0) {
...
}
For engineering purposes not the best, but you lose the overhead of
a loop (and no additional scopes to enter), and gain the benefit of
skipping the rest of the tests if one fails.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: Sun, 19 Feb 2006 07:55:51 -0800
From: "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail@moderncppdesign.com>
Subject: Re: The inverse problem: generate all instances of a regexp
Message-Id: <Iuxyx4.24GA@beaver.cs.washington.edu>
Frederic Beal wrote:
> "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail@moderncppdesign.com> writes:
>
>> I wonder how this could be done elegantly. Given a regular expression
>> $re, write a function Generate($) that returns a list of all possible
>> strings that could match $re. If the set is infinite, die with an
>> error message.
>>
>> For example, if $re = '(debug|release)/progname\.(c|h)', Generate($re)
>> should return four strings:
>>
>> 'debug/progname.c'
>> 'debug/progname.h'
>> 'release/progname.c'
>> 'release/progname.h'
>>
>> If, on the other hand, $re = '(debug/release)/.*\.(c|h)' then
>> Generate($re) should die.
>>
>> Any ideas on how to do that in a clever manner? (The only way that I
>> think of is to parse $re and use recursion etc.)
>
> From a theoretical point of view : the easiest way to do what you want is to
> turn your regular expression into a finite automaton (see, for example,
> http://lambda.uta.edu/cse5317/spring01/notes/node9.html
> and nodes around). Then, enumerating the words recognized by a f.a. or
> telling if it matches an infinite set of words is easy. I give a simple
> implementation of it at the end of this message. Here is a simple
> example of use:
[snip]
Thanks a lot for your idea and code, Frederic. I'll use them; the
problem that remains is parsing the darn regular expression :o). But, I
approach it on a need basis.
Andrei
------------------------------
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 8972
***************************************