[24256] in Perl-Users-Digest
Perl-Users Digest, Issue: 6447 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 22 18:15:43 2004
Date: Thu, 22 Apr 2004 15:15:14 -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, 22 Apr 2004 Volume: 10 Number: 6447
Today's topics:
Re: perl -d interfering with program execution? <nospam-abuse@ilyaz.org>
Re: perl -d interfering with program execution? <news**NO_SPAM**@psychogenic.com>
Perl and .NET Integration Solution (lingya)
Re: regular expressions for postgres syntax <jan.biel@tu-clausthal.de>
Re: slurp not working? ideas please! <remorse@partners.org>
Re: slurp not working? ideas please! <remorse@partners.org>
Re: slurp not working? ideas please! <tassilo.parseval@rwth-aachen.de>
Re: sort numeric lists (christie)
Re: sort numeric lists <uri.guttman@fmr.com>
Using alarm: Timeout to do something else. (Prabh)
Re: Using alarm: Timeout to do something else. <1usa@llenroc.ude>
Re: Writing dupliactes to database file (Testor)
Re: Writing dupliactes to database file <tore@aursand.no>
Re: XML::Xerces questions <apollock11@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 22 Apr 2004 18:04:34 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: perl -d interfering with program execution?
Message-Id: <c691fi$2d9g$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Pat Deegan
<news**NO_SPAM**@psychogenic.com>], who wrote in article <pan.2004.04.22.14.16.36.828402@psychogenic.com>:
> As stated, this regex (from DBI.pm):
>
> /^dbi:(\w*?)(?:\((.*?)\))?:(.*)/i
>
> works fine under normal execution but fails under 'perl -d'. However,
> everything works ok under both 'perl' and 'perl -d' if I edit the DBI.pm
> file and remove the 'i' modifier
Check the data it is matched against, and whether you can reproduce th
failure in a standalone perl. If not, I suspect a bug in DBI XS code,
which may write over the a spurious pointer, breaking some Perl table.
Another hint: enable REx debugging, and see what differs between these
situations.
Hope this helps,
Ilya
------------------------------
Date: Thu, 22 Apr 2004 17:35:16 -0400
From: "Pat Deegan" <news**NO_SPAM**@psychogenic.com>
Subject: Re: perl -d interfering with program execution?
Message-Id: <pan.2004.04.22.21.35.15.893737@psychogenic.com>
Hello and thanks for your response,
On Thu, 22 Apr 2004 18:04:34 +0000, Ilya Zakharevich wrote:
>
> Check the data it is matched against, and whether you can reproduce th
> failure in a standalone perl. If not, I suspect a bug in DBI XS code,
> which may write over the a spurious pointer, breaking some Perl table.
My main question here is: why would this only happen under the -d
debugger?
> Another hint: enable REx debugging, and see what differs between these
> situations.
Ah, this is interesting. I've gone through the joyous process of
compiling and installing the latest stable Perl (and just about every
third party module I use), with -DDEBUGGING enabled in order to run the
program with the -Dr switch.
The same behavior is repeated.
The entire process is about 10 times longer when running 'perl -Dr
./myapp.pl' than when I use 'perl -Dr -d ./myapp.pl'. With -d the REx
match fails like this:
Matching REx `^dbi:(\w*?)(?:\((.*?)\))?:' against
`dbi:mysql:database=mydb;host=localhost'
Setting an EVAL scope, savestack=223
0 <> <dbi:mysql:database=mydb;host=localhost> | 1: BOL 0 <>
<dbi:mysql:database=mydb;host=localhost> | 2: EXACTF <dbi:>
Guessing start of match, REx `^_<' against
`/usr/lib/perl5/5.8.3/utf8.pm'... String not equal...
Match rejected by optimizer
And here is the relevent portion of output when running standalone:
Matching REx `^dbi:(\w*?)(?:\((.*?)\))?:' against
`dbi:mysql:database=mydb;host=localhost'
Setting an EVAL scope, savestack=132
0 <> <dbi:mysql:database=mydb;host=localhost> | 1: BOL 0 <>
<dbi:mysql:database=mydb;host=localhost> | 2: EXACTF <dbi:> 4
<dbi:> <mysql:database=mydb;host=localhost> | 4: OPEN1 4
<dbi:> <mysql:database=mydb;host=localhost> | 6: MINMOD 4
<dbi:> <mysql:database=mydb;host=localhost> | 7: STAR
Setting an EVAL scope, savestack=132
... goes on for a long time, then ...
9 <mysql> <:database=mydb;host=localhost> | 25: NOTHING 9
<mysql> <:database=mydb;host=localhost> | 26: EXACTF <:>
10 <ysql:> <database=mydb;host=localhost> | 28: END
Match successful!
So why does the re engine start
"Guessing start of match, REx `^_<' against `/usr/lib/perl5/5.8.3/utf8.pm'..."
when running 'perl -d ./myapp.pl' and not with just 'perl ./myapp.pl'?
Thanks for your assistance :)
--
Pat Deegan,
http://www.psychogenic.com/
Registered Linux User #128131
------------------------------
Date: 22 Apr 2004 09:17:53 -0700
From: lingya@datasophy.com (lingya)
Subject: Perl and .NET Integration Solution
Message-Id: <befc620c.0404220817.7787a5bb@posting.google.com>
Datasophy Technologies is pleased to announce the public release of
dotNET for Perl, a .NET integration tool for Perl programmers. dotNET
for Perl grows from Datasophy's consulting work, and now is made
available to general public.
By using dotNET for Perl, Perl programmers can use any .NET components
as part of their vast Perl package collections, and can integrate .NET
services and components into their applications easily and seamlessly.
It further enhances Perl as a glue language for integrating various
technologies and components together. With the agility of Perl as a
scripting language, programmers can prototype, experiment and explore
features of .NET services and components quickly and easily, and can
enhance and integrate their existing CGI scripts, database access
scripts and other Perl based applications with any available .NET
components.
To download a copy of dotNET for Perl, please visit
http://www.datasophy.com/download.html.
------------------------------
Date: Thu, 22 Apr 2004 23:05:58 +0200
From: "Jan Biel" <jan.biel@tu-clausthal.de>
Subject: Re: regular expressions for postgres syntax
Message-Id: <c69ctd$c56$1@ariadne.rz.tu-clausthal.de>
Jack Challen wrote:
> You want a parser.
> In fact, you want SQL::Parser, or SQL::Translator::Parser::PostgreSQL
>
> http://search.cpan.org/search?query=sql%3A%3Aparser&mode=module
>
http://search.cpan.org/~kclark/SQL-Translator-0.05/lib/SQL/Translator/Parser/PostgreSQL.pm
> -or-
> http://tinyurl.com/yruzd
Thanks a bunch, exactly what I need (I guess). Didn't know there were
parsers available just like that, like standalone parsers outside of
compilers.
Yes, I still have a lot to learn :)
Thanks anyway,
Janbiel
------------------------------
Date: Thu, 22 Apr 2004 15:23:07 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: slurp not working? ideas please!
Message-Id: <remorse-B7AA89.15230622042004@plato.harvard.edu>
In article <c65enp$8cdgo$1@ID-231055.news.uni-berlin.de>,
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote:
> The reason is that File::File::find() also returns directory names, most
> notably "." and ".." as well. Have it return early when the current file
> is not one that you want to process:
>
> find sub {
> return if /^\.\.?/; # catches "." and ".."
> my $name = $_;
> ...
> }, $dir;
I'm not sure exactly how you would get the directory name here (I've not
had the pleasure of using File::Find yet), but wouldn't it be better to
do something like:
find sub {
return if -d (some_function_to_get_cwd() . $_);
...
}
? This would handle any other miscellaneous directories that appear...
Ricky
--
Pukku
------------------------------
Date: Thu, 22 Apr 2004 15:27:41 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: slurp not working? ideas please!
Message-Id: <remorse-15908D.15274122042004@plato.harvard.edu>
In article <96fa801ru1jr3at8f3bek7jj2j3bli0am6@4ax.com>,
Geoff Cox <geoffacox@dontspamblueyonder.co.uk> wrote:
> Anno
>
> the code as of now follows - I am confused re how the OOP fits in with
> the File::Find ... but as I am using html files in the 1 folder have
> removed the File::Find part .. but still get the warning re
> uninitialized value in pattern match for the
>
> if ($next3 =~ /\$i\<(\d+);/) {
>
> in sub classroomnotes
>
> any ideas why?
>
Try doing the following:
> package MyParser;
> use base qw(HTML::Parser);
>
[snip]
> sub classroomnotes {
>
> my ($pattern) = @_;
>
> # print ("\$pattern has value $pattern \n");
>
> open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php") ||
> die "cannot open d:/a-keep9/short-nondb/allphp/allphp2.php \n";
>
> my $line = <INNN>;
# since I don't see a chomp/chop anywhere, I'm assuming
# that each line has a newline at the end already.
print "line: ", $line;
>
> while (<INNN>){
> last if /$pattern/;
> }
> my ($curr, $next1, $next2, $next3) = <INNN>;
print "curr: ", $curr;
print "next1: ", $next1;
print "next2: ", $next2;
print "next3: ", $next3;
print "\n";
> close (INNN);
>
> if ($next3 =~ /\$i\<(\d+);/) {
> my $nn = $1;
> print OUT ("<td valign='top'> \n");
> for ($c=1;$c<$nn;$c++) {
> print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" . '">' .
> "Document$c" . "</a><br>" . "\n");
> }
> print OUT ("</td></tr>\n");
> }
> }
>
What does this tell you?
Ricky
--
Pukku
------------------------------
Date: 22 Apr 2004 21:28:00 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: slurp not working? ideas please!
Message-Id: <c69dd0$9ln8d$1@ID-231055.news.uni-berlin.de>
Also sprach Richard Morse:
> In article <c65enp$8cdgo$1@ID-231055.news.uni-berlin.de>,
> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote:
>
>> The reason is that File::File::find() also returns directory names, most
>> notably "." and ".." as well. Have it return early when the current file
>> is not one that you want to process:
>>
>> find sub {
>> return if /^\.\.?/; # catches "." and ".."
>> my $name = $_;
>> ...
>> }, $dir;
>
> I'm not sure exactly how you would get the directory name here (I've not
> had the pleasure of using File::Find yet), but wouldn't it be better to
> do something like:
>
> find sub {
> return if -d (some_function_to_get_cwd() . $_);
> ...
> }
>
> ? This would handle any other miscellaneous directories that appear...
Yes, a -d check would be more generic and not skip dotfiles (for example).
As the OP wants to parse a certain type of file, he might also just
allow only files with a certain extension as in
find sub {
return unless /\.html$/;
...
}
Btw:
some_function_to_get_cwd() . $_
becomes
$File::Find::name
in the File::Find lingo.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 22 Apr 2004 11:41:35 -0700
From: kenvin007@yahoo.com (christie)
Subject: Re: sort numeric lists
Message-Id: <f977ee23.0404221041.2d45334d@posting.google.com>
Uri Guttman <uri.guttman@fmr.com> wrote in message news:<sisc7jw95man.fsf@tripoli.fmr.com>...
> >>>>> "TKoPaP" == The King of Pots and Pans <King@ask.for.email.invalid> writes:
>
> TKoPaP> On Wed, 21 Apr 2004 at 12:48 GMT, Uri Guttman spoke:
> >> this isn't better, it is correct. see my other post where i divined
> >> his problem without even seeing any code. :)
>
> TKoPaP> I appreciate your insight in this matter. You appear to have extensive
> TKoPaP> education in this area.
>
> TKoPaP> For this problem I can only use the standard modules that come
> TKoPaP> with Perl 5.6. Is perl 5.6 up to the task? Or can the solution
> TKoPaP> only be had by downloading your module?
>
> you can do a multikey sort with any perl. you can also do the multipass
> sort mentioned in this thread. both require you to understand some more
> about sorting in general but neither is that complicated. and you have
> been given enough code and clues in this thread to solve your
> problem. so hack it up in a small script and if you can't get to work,
> post that code back here. but you have to do the homework first so study
> the examples and ideas posted already.
>
> uri
=============================================================
Guys.... Have you heard simplicity is beauty. Don't make your life
more complited than it is.
Here is a hint
9 2 6
5 1 6
using split to differenciate first and second row.
push 9 2 &6 into arr_tmp1
push 5 1 &6 into arr_tmp2
push arr_tmp1[0] & arr_tmp2[0] into array1
push arr_tmp1[1] & arr_tmp2[1] into array2
push arr_tmp1[2] & arr_tmp2[2] into array3
Just sort the array{1-3} . Sort array{1-3} == sort column{1-3}
To display, well.... you know how to display it.
------------------------------
Date: 22 Apr 2004 16:20:27 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: sort numeric lists
Message-Id: <siscsmev4vec.fsf@tripoli.fmr.com>
>>>>> "c" == christie <kenvin007@yahoo.com> writes:
c> Guys.... Have you heard simplicity is beauty. Don't make your life
c> more complited than it is.
my life is very complite. :)
c> Here is a hint
oh boy! i need one of those!
c> 9 2 6
c> 5 1 6
c> using split to differenciate first and second row.
hmm, the OP already had those in an list of lists. why is split needed?
c> push 9 2 &6 into arr_tmp1
c> push 5 1 &6 into arr_tmp2
and what language is that written in?
c> push arr_tmp1[0] & arr_tmp2[0] into array1
c> push arr_tmp1[1] & arr_tmp2[1] into array2
c> push arr_tmp1[2] & arr_tmp2[2] into array3
and what language is that written in?
that isn't even legal pseudo-code! :)
c> Just sort the array{1-3} . Sort array{1-3} == sort column{1-3}
and how does that sort multiple columns?
and your working code is where?
and how do you extend that beyond 2 rows of 3 numbers each?
what are you talking about?
try a little more complication in your life. being correct is better
than being simple.
uri
------------------------------
Date: 22 Apr 2004 08:27:58 -0700
From: Prab_kar@hotmail.com (Prabh)
Subject: Using alarm: Timeout to do something else.
Message-Id: <e7774537.0404220727.5c3405b6@posting.google.com>
Hello all,
I need to monitor availability of a webserver for x no. of sec.s and
trigger
an alert mechanism after the time elapses and webserver still doesnt
respond.
Am thinking of using the 'alarm' function to do this, along the lines,
==========================================
use LWP::Simple ;
alarm(60) ;
my $url = head("http://abc.xyz.com") ;
==========================================
When the webserver doesnt respond after 60 sec.s, I want to shoot off
a mail to the webadmins that the webserver isnt responding. So, where
do I get the "at this point 60 sec.s have elapsed and theres no
reponse from webserver, its ok to send mail now" point.
Paraphrasing the alarm example from the Camel book:
===========================================
print "Answer in 60 sec.s\n" ;
alarm(60) ;
$answer = <STDIN> ;
$timeleft = alarm(0) ;
print "You had $timeleft sec.s remaining.\n" ;
===========================================
I here, where do I print "Hey, 60 sec.s elapsed and you still didnt
answer. Goodbye." All I get after 60 sec.s is the message "Alarm
clock". I dont know where its coming from.
Thanks for your time,
Prab
------------------------------
Date: 22 Apr 2004 16:34:42 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Using alarm: Timeout to do something else.
Message-Id: <Xns94D37FF531EF6asu1cornelledu@132.236.56.8>
Prab_kar@hotmail.com (Prabh) wrote in news:e7774537.0404220727.5c3405b6
@posting.google.com:
> Am thinking of using the 'alarm' function to do this, along the lines,
Then do read the documentation for the alarm function.
> Paraphrasing the alarm example from the Camel book:
I do not have the Camel book here with me so I cannot comment on the
extent of the 'paraphrasing' you have done.
> ===========================================
> print "Answer in 60 sec.s\n" ;
> alarm(60) ;
> $answer = <STDIN> ;
> $timeleft = alarm(0) ;
> print "You had $timeleft sec.s remaining.\n" ;
> ===========================================
>
> I here, where do I print "Hey, 60 sec.s elapsed and you still didnt
> answer. Goodbye." All I get after 60 sec.s is the message "Alarm
> clock". I dont know where its coming from.
What part of the documentation for the alarm function is not clear?
#! /usr/bin/perl
use strict;
use warnings;
my $timeleft = 60;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeleft;
my $input = <STDIN>;
$timeleft = alarm 0;
};
if ($@) {
die unless $@ eq "alarm\n";
print "You took too long to respond!\n";
} else {
print "You had $timeleft seconds remaining.\n"
}
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: 22 Apr 2004 08:07:29 -0700
From: extended@operamail.com (Testor)
Subject: Re: Writing dupliactes to database file
Message-Id: <19789ad6.0404220707.4c42526@posting.google.com>
Tore Aursand <tore@aursand.no> wrote in message news:<pan.2004.04.21.19.15.19.673731@aursand.no>...
> On Wed, 21 Apr 2004 10:02:44 -0700, Testor wrote:
> > open(DATABASE, ">>bnkrecpts.db") or die "Can't write open file.
> > Reason: $!";
> > seek(DATABASE,0,2);
> > print DATABASE "$myreceipt\n";
> > close(DATABASE);
> >
> > This works OK though not sure if it's the best way because I'm writing
> > duplicate receipt numbers. I tried to use an if statement to make sure
> > is the number exists in the file before writing it but I'm afraid I
> > wasn't successful I did something like:
> >
> > open (THERECEIPT, "bnkrecpts.db") or die "Can't open file. Because:
> > $!";
> > flock(THERECEIPT,2);
> > $receiptnum = <THERECEIPT>;
> > close (THERECEIPT);
> >
> > if ($receiptnum eq $myreceipt) {
> > stop and redirect or print something to the page etc..
> >
> > }
>
> This is partly answered in the Perl FAQ;
>
> perldoc -q duplicate
>
> Anyway. You could take a look at the following code which might help you
> get a clue;
>
> my $filename = 'bnkrecpts.db';
> my $receipt = $query->param('receipt') || '';
>
> if ( $receipt ) {
> my $receipt_exists = 0;
>
> open( THERECEIPT, '<', $filename ) or die "$!\n";
> while ( <THERECEIPT> ) {
> chomp;
> if ( $_ eq $receipt ) {
> $receipt_exists++;
> last;
> }
> }
> close( THERECEIPT );
>
> unless ( $receipt_exists ) {
> open( THERECEIPT, '>>', $filename ) or die "$!\n";
> print THERECEIPT "$receipt\n";
> close( THERECEIPT );
> }
> }
>
> Fill in with file locking etc. as it suits you. The code above is a
> simple example and has not been tested or anything.
>
> Hope it helps, though.
Tore,
It worked just fine the first time. I was hoping it fails so I spend
sometime trying to make it work, that way, I will learn more.
Of course, couple of questions came to mind:
1- Do I have to do any flocking if it's only one script that's opening
and writing to the file?
2- What about seek? don't I have to rewind? or it's not needed in this
case?
3- I inserted a print location like so:
if ( $_ eq $receipt ) {
$receipt_exists++;
print "Location: test.html\n\n";
last;
That worked too, any problem in doing so?
Thanks,
------------------------------
Date: Thu, 22 Apr 2004 19:51:37 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Writing dupliactes to database file
Message-Id: <pan.2004.04.22.17.48.37.550769@aursand.no>
On Thu, 22 Apr 2004 08:07:29 -0700, Testor wrote:
> 1- Do I have to do any flocking if it's only one script that's opening
> and writing to the file?
It doesn't matter how many scripts. What matters is if the script(s) will
try to access the file simulatenously.
If you are _absolutely_ sure that there will be only one script at a time,
and only one instance of that script, you don't need file-locking.
> 2- What about seek? don't I have to rewind? or it's not needed in this
> case?
Not in this case, as I see it; Whenever you open a file, the "file
cursor" will position itself at the very beginning of the file. If you
are opening a file in "append mode" (ie. '>>'), whatever written to the
file will be appended to the file.
> 3- I inserted a print location like so:
>
> if ( $_ eq $receipt ) {
> $receipt_exists++;
> print "Location: test.html\n\n";
> last;
>
> That worked too, any problem in doing so?
Not really, but the code above won't work if you're not local; 'test.html'
only exists on the server (ie. where the script is running), right?
Anyway. You should consider letting the CGI.pm module take care of any
redirects, so that you're sure that you'll get it 100% correct. Read the
documentation for the CGI.pm module for more information.
--
Tore Aursand <tore@aursand.no>
"Every man usually has something he can do better than anyone else.
Usually it is reading his own handwriting." (Unknown)
------------------------------
Date: Thu, 22 Apr 2004 13:26:11 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Re: XML::Xerces questions
Message-Id: <c699p5$2gb5$1@agate.berkeley.edu>
> and you can call methods on it to examine the error.
Thanks! This makes things conceptually clearer for me.
Steven N. Hirsch wrote:
> pkent wrote:
>
> > One underused (IME) feature of perl >5.005 are exception objects. This
> > is where you call die() with an object, not a string. The object then
> > ends up in $@ and you can call methods on it to examine the error.
> > While this doesn't have Java's stricter model exceptions, it can still
> > help out in cases like yours where currently you're just getting an
> > error _string_ and you want to parse that string in some way or get
> > other information.
>
>
> XML::Xerces uses exception objects.
------------------------------
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 6447
***************************************