[26055] in Perl-Users-Digest
Perl-Users Digest, Issue: 8265 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 21 10:41:37 2005
Date: Thu, 21 Jul 2005 03:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 21 Jul 2005 Volume: 10 Number: 8265
Today's topics:
Error.pm and try/catch/throw <BLOCKSPAMfishfry@your-mailbox.com>
Re: How to send a query to the browser from time to tim <joe@inwap.com>
New version of DBD::mysql problems - ? in strings. <not@invalid.invalid>
Re: Regex (?(?{CODE})) has too many branches <abigail@abigail.nl>
Re: Regex (?(?{CODE})) has too many branches <No_4@dsl.pipex.com>
Strange speed-increase by separating "if"s <w.n.humann.removethis@agilent.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 20 Jul 2005 22:54:02 -0700
From: fishfry <BLOCKSPAMfishfry@your-mailbox.com>
Subject: Error.pm and try/catch/throw
Message-Id: <BLOCKSPAMfishfry-D36AD2.22540220072005@comcast.dca.giganews.com>
Is Error.pm the standard way to do error handling these days? Or at
least *a* standard way?
Are there any standard or popular libraries of exceptions, or should I
just write my own Error.pm subclasses?
------------------------------
Date: Thu, 21 Jul 2005 02:37:16 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: How to send a query to the browser from time to time?
Message-Id: <d7OdncnLE59N8ULfRVn-2Q@comcast.com>
Subject: How to send a query to the browser from time to time?
Answer: You don't. Queries come from the browser, not to it.
Admin wrote:
> I am creating a chat application like Messenger for the web (using the
> browser) and I'm wondering if there is a way to
> receive new messages from time to time from the server other than
> refreshing the page each 5 sec.
The HTTP protocol is not interactive.
The usual way of getting updates like that is to have an HTML
page with an embedded Java applet running. There are many
IRC clients written in Java that run inside a browser window.
This is not a perl-specific question.
-Joe
------------------------------
Date: Thu, 21 Jul 2005 14:47:04 +1000
From: Matthew Braid <not@invalid.invalid>
Subject: New version of DBD::mysql problems - ? in strings.
Message-Id: <dbn9c8$1lsa$1@bunyip2.cc.uq.edu.au>
Hi all,
We just did a package upgrade of DBD::mysql to version 3.001 (freebsd
system). All looked ok until one particular example showed a problem
with the quote function - specifically, it wastreating the '?' character
oddly.
Previously this code (with the connection stuff filled in):
my $dbh = DBI->connect(...);
my $query =
"INSERT INTO test (t1, t2) VALUES (?, " . $dbh->quote("?") . ")";
print $query, "\n";
my $sth = $dbh->prepare($query);
$sth->execute('Question Mark');
print "OK!\n";
resulted in:
INSERT INTO test (t1, t2) VALUES (?, '?')
OK!
With version 3.001 of DBD::mysql, this becomes:
INSERT INTO test (t1, t2) VALUES (?, '?')
DBD::mysql::st execute failed: called with 1 bind variables when 2 are
needed
In other words, the ? inside the string is being interpreted as a
binding marker, when it shouldn't.
We've reverted back to the old version (2.9008) and I'm sending this
message (or close to) to the perl mysql list, but its something people
should look out for - was a bit of a weird bug to find :)
MB
------------------------------
Date: 20 Jul 2005 23:30:43 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regex (?(?{CODE})) has too many branches
Message-Id: <slrnddtnl3.7fo.abigail@alexandra.abigail.nl>
James Taylor (spam-block-@-SEE-MY-SIG.com) wrote on MMMMCCCXLI September
MCMXCIII in <URL:news:ant2018480e6fNdQ@riscpc.jtnet>:
`' In article <slrndds09k.7fo.abigail@alexandra.abigail.nl>,
`' Abigail <abigail@abigail.nl> wrote:
`' >
`' > James Taylor wrote:
`' > >
`' > > my ($table) = $page =~ m{
`' > > (?> <table\b.*?> (.*?) </table> ) # Get table
`' > > (?(?{
`' > > $1 !~ /<table\b/i && # Mustn't contain a table
`' > > $1 =~ /\bclass="whiteHeading"/i # Must have white headings
`' > > }) | _FAIL_ )
`' > > }six;
`' > >
`' > > Unfortunately, this generates the following error:
`' > >
`' > > /\bclass="whiteHeading"/: Switch (?(condition)... contains too
`' > > many branches at myprog line 66.
`' >
`' >
`' > The regex engine is not re-entrant,
`' [snip]
`'
`' > Use index().
`'
`'
`' Aha! Thanks for that. After spending some time trying to work
`' out why index() wasn't working, I eventually tried index
`' without brackets and got the following to compile and run:
`'
`' my ($table) = $page =~ m{
`'
`' # Get a table without backtracking
`' (?> <table\b.*?> (.*?) </table> )
`'
`' # Put a lowercase copy of its content in $content
`' (?{ local $content = lc $1; })
`'
`' # Check it does not contain another table
`' (?(?{ -1 == index $content, '<table' }) | --FAIL-- )
`'
`' # Debug message
`' (?{ print "Top level table found\n"; })
`'
`' # Check it does contain a white heading
`' (?(?{ -1 != index $content, 'class="whiteHeading"' }) | --FAIL-- )
`'
`' # Debug message
`' (?{ print "Matched\n" })
`'
`' }six;
`'
`' This prints "Top level table found\n" 25 times and falls through
`' without matching. Further investigation reveals that at the point
`' $1 is assigned to $content, it is still set to the result of
`' a *previous* match from further up in my program! This is why
`' both assertions fail to find what they're looking for, of course.
`' However, the Camel book (3rd ed) demonstrates (on page 213)
`' that code blocks *can* access backreferences from earlier in
`' the current match. So, what am I doing wrong?
`'
`' I'm starting to worry that this may be a bug in my particular
`' copy of perl. I'm running the RISC OS port which reports as:
`'
`' This is perl, version 5.005_03 built for arm-riscos
`'
`' Copyright 1987-1999, Larry Wall
`'
`' RISC OS port by Andrew Black and Nicholas Clark (1998),
`' Steve Ellacott (1996), Luke Taylor (1995) and Paul Moore (1990).
`' Release 1.13
`'
`' Unfortunately, there isn't a more up to date version available
`' for RISC OS (at least not one that works fully) so I'm stuck.
`' Can anyone help?
I'd write that as (untested):
m{ <table\b [^"'>]* (?: (?: "[^"]*" | '[^']*' ) [^"']*) * >
[^<c]* (?: (?: <(?!table) | c(?!lass="whiteHeading") ) [^<c]* )*
</table>
}xi;
It'll fail to match if there's a `class="whiteHeading"' outside a tag
something like `<!-- <table> -->' in the text, but your code doesn't
check for that either.
--
sub _ {$_ = shift and y/b-yB-Y/a-yB-Y/ xor !@ _?
exit print :
print and push @_ => shift and goto &{(caller (0)) [3]}}
split // => "KsvQtbuf fbsodpmu\ni flsI " xor & _
------------------------------
Date: Thu, 21 Jul 2005 00:36:56 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Regex (?(?{CODE})) has too many branches
Message-Id: <ua-dnSRXDdGGfUPfRVnytg@pipex.net>
> James Taylor (spam-block-@-SEE-MY-SIG.com) wrote on MMMMCCCXLI September
>
> `' However, the Camel book (3rd ed) demonstrates (on page 213)
> `' that code blocks *can* access backreferences from earlier in
> `' the current match. So, what am I doing wrong?
(Wild guessing here...)
Don't you need \1 rather than $1 for that?
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Thu, 21 Jul 2005 11:51:43 +0200
From: Wolfram Humann <w.n.humann.removethis@agilent.com>
Subject: Strange speed-increase by separating "if"s
Message-Id: <42df702f$0$18025$9b4e6d93@newsread4.arcor-online.net>
I have a script for processing certain eps-files. What it basically does
is going through the file looking for "setgray"-lines. If it finds one,
it checks if it's followed by lines matching the values in @head and
then @dot (plus some coordinate-checks). If all matches, @head remains
in the file while @dot is discarded. If the match fails, the file
remains unchanged. Here is the script:
#!/usr/local/bin/perl -w
use strict;
my @head = (
'^N(\s+\d+)(\s+\d+)(\s+\d+) 0 360 arc sf N$',
'^\d+\s+slw$',
);
my @dot = (
'^(\d+)\s+(\d+)\s+M$',
('^(\d+)\s+(\d+)\s+D$') x 72,
);
my @c_head = map qr/$_/, @head;
my @c_dot = map qr/$_/, @dot;
my ($x, $y, $r);
while(<>)
{
print;
if(/^[0-9.]+\s+setgray\s+$/)
{
my ($h, $d) = (0,0);
my $l = "";
while(<>)
{
if ($head[$h])
{
print;
last unless $_ =~ $c_head[$h];
($x, $y, $r) = ($1, $2, $3) if defined $3;
$h++;
}
elsif ($dot[$d])
{
$l .= $_;
if ($_ !~ /$c_dot[$d]/ or
$1 < $x - $r - 2 or
$1 > $x + $r + 2 or
$2 < $y - $r - 2 or
$2 > $y + $r + 2 )
{
print $l;
last;
}
$d++;
}
else
{
print $l if /^\d+\s+\d+\s+D$/;
print;
last;
}
}
}
}
I was surprised how long it took and profiled with Devel::SmallProf.
This showed that most time is spent in "if (($_ !~ /$c_dot[$d]/) or...".
To see if the pattern match or the comparisons took so long, I split the
"if" like this:
if ($_ !~ /$c_dot[$d]/)
{
if ($1 < $x - $r - 2 or
$1 > $x + $r + 2 or
$2 < $y - $r - 2 or
$2 > $y + $r + 2 )
{
print $l;
last;
}
}
To my surprise a test run (without the profiler) ran *at least* twice as
fast as the original version. Also, the profiler says that "no time" is
spent for the comparisons and the time for the pattern match dropped to
one third of what is was before.
Any explanation?
Thanks,
Wolfram
------------------------------
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 8265
***************************************