[17383] in Perl-Users-Digest
Perl-Users Digest, Issue: 4805 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 3 14:05:55 2000
Date: Fri, 3 Nov 2000 11:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973278309-v9-i4805@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 3 Nov 2000 Volume: 9 Number: 4805
Today's topics:
Re: #! syntax <bart.lateur@skynet.be>
Re: 1+(-1)=? can be 0 or 2, depending on context <ren.maddox@tivoli.com>
Re: 1+(-1)=? can be 0 or 2, depending on context (Helmut Richter)
Re: 1+(-1)=? can be 0 or 2, depending on context <joe+usenet@sunstarsys.com>
Re: CGI slow, command line fast ? chronofish@my-deja.com
Re: Communicating with a child process <ren.maddox@tivoli.com>
Re: Continuous file modification age monitor (Tom Christiansen)
does anyone know if this will work? wildhorses@my-deja.com
Re: Duplicate lInes in File count and del routine jkipp@mbna.com
Re: Duplicate lInes in File count and del routine jkipp@mbna.com
Re: efficiently passing objects <bkennedy99@home.com>
Freelance Programmer Neede - Good Money <lee@areality.co.uk>
Re: Freelance Programmer Neede - Good Money (Michel Dalle)
Re: Freelance Programmer Neede - Good Money (David H. Adler)
Re: Getting Perl to wait for another Program <ren.maddox@tivoli.com>
Re: How do I get the html source code from a page on an <jboes@eomonitor.com>
Re: INTERACTIVE DEBUGGER !!?? <jboes@eomonitor.com>
Re: Need suggestions on optimization <ren.maddox@tivoli.com>
Re: Need suggestions on optimization <elijah@workspot.net>
Re: Onload right or wrong <markscott@barclays.net>
Re: Perl Question <rosie@dozyrosy.plus.com>
Re: Postprocessing output to a file <bart.lateur@skynet.be>
Problems using MIME::Lite and SMTP <Aidan.Dunphy@orchard-systems.co.uk>
Timers? <lostshade@home.com>
Re: values of strings <ren.maddox@tivoli.com>
Re: Want to process all files less than 24 hours old (Jerome O'Neil)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 03 Nov 2000 19:00:06 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: #! syntax
Message-Id: <3i260tssiejku8htblo82r069bo28v44jr@4ax.com>
Kuang-chun Cheng wrote:
> In tcl/tk, I can use
>
> #!/bin/sh
> # \
> exec wish "$0" ${1+"$@"}
>
> to avoid using absolute path of wish after #!. Simply
> replace wish by perl doesn't work.
>
> My question is, how to use #! syntax to invoke perl if I
> don't know where perl is installed.
There's that mysterious "if $running_under_some_shell" trick. I think
that is what it's for. The argument string is valid Perl, but never
executed because this variable is not defined, hence not true.
See any script that is included with your Perl distribution.
--
Bart.
------------------------------
Date: 03 Nov 2000 09:41:29 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <m38zr1yseu.fsf@dhcp11-177.support.tivoli.com>
Joe Schaefer <joe+usenet@sunstarsys.com> writes:
> ---------------------
> #! /usr/bin/perl -w
>
> my $coe = 1;
> $coe = "-$coe";
>
> print "String: $coe\n";
> print "Numeric: ", $coe+0, "\n";
> --------------------
>
> On linux 5.005_03, here's my output:
>
> String: -1
> Numeric: -1
>
> On 5.6, I get:
>
> String: -1
> Numeric: 1
>
> % perl -v
>
> This is perl, v5.6.0 built for i586-linux
On 5.6, I get:
String: -1
Numeric: -1
% perl -v
This is perl, v5.6.0 built for i686-linux-thread-multi
> My 5.6 is a few months old, so this issue might have
> been resolved in your version.
>
>
> Is there any mention of such a problem in your changelogs?
Nothing obvious. The only things close are:
[ 6191] By: gsar on 2000/06/01 09:38:21
Log: vec() loses numericalness (modified version of patch suggested
by Robin Barker)
Branch: perl
! doop.c t/op/vec.t
[ 5983] By: gsar on 2000/04/28 07:15:04
Log: numeric conversion of non-number in change#3378 tramples on
OOK offset, causing segfaults
Branch: perl
! sv.c
[ 6002] By: gsar on 2000/04/28 19:34:16
Log: destructive sv_setsv() can lose UV-ness from source, causing
numeric promotions/comparisons to fail to do the right thing
Branch: perl
! sv.c
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 3 Nov 2000 18:17:54 GMT
From: Helmut.Richter@lrz-muenchen.de (Helmut Richter)
Subject: Re: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <8tuvgi$o4v$1@wsc10.lrz-muenchen.de>
First of all, thanks to all who responded. Yes, it really looks like a
bug. I am always very reluctant to suspect interpreter bugs, and
therefore I wanted some more people to have a look into it. Thanks
again.
Joe Schaefer <joe+usenet@sunstarsys.com> writes:
>I guess no one is able to reproduce the problem you're having
>except me. My output for
>% perl -v
>This is perl, v5.6.0 built for i586-linux
>is (warnings enabled)
>[...]
>If that's too much trouble, a quick fix would be to change
>$coe = "$op$coe";
>to
>$coe = "$op$coe" + 0;
Are you sure that works? This might just change the -1 into a 1 some
statements earlier.
>However, I strongly recommend upgrading your perl executable as well,
>because if the same chef that served you this fine piece of
>italian quisine is responsible for the rest of your program,
>you're probably going to bang into a few more bugs. The
>code snippet you sent belongs in a regression suite, not in
>a real live piece of software.
That's why I am not willing to use the other work-around either, which
I gave in my original description.
>I have a feeling that the entire chunk of code can be effectively
>reduced to no more than a few lines, but in case you are the
>chef, I don't want to humiliate you for being so forthcoming with
>your troubles.
There is always more than one way to do it in perl, and I am always
open to learn new things. So I won't feel humiliated if someone comes
up with a smarter way to do it.
One could of course have started with a while loop on the potential
first terms instead of splitting the thing into an array. The REs
would have been a little more difficult to oversee (but REs is the
last thing I am afraid of) but the code a little shorter. The
associative array is still needed for recognising a variable occurring
more than once, and the array of positions for ordering the variables
into their previous order (which is a matter of taste: should n+i-2n
really become -n+i or better i-n). Under these constraints not much
would be saved unless someone has a real different, real smart idea.
Helmut Richter
------------------------------
Date: 03 Nov 2000 13:40:01 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <m38zr0yk5a.fsf@mumonkan.sunstarsys.com>
Ren Maddox <ren.maddox@tivoli.com> writes:
> Nothing obvious. The only things close are:
>
> [ 6191] By: gsar on 2000/06/01 09:38:21
> Log: vec() loses numericalness (modified version of patch suggested
> by Robin Barker)
> Branch: perl
> ! doop.c t/op/vec.t
>
> [ 5983] By: gsar on 2000/04/28 07:15:04
> Log: numeric conversion of non-number in change#3378 tramples on
> OOK offset, causing segfaults
> Branch: perl
> ! sv.c
>
> [ 6002] By: gsar on 2000/04/28 19:34:16
> Log: destructive sv_setsv() can lose UV-ness from source, causing
> numeric promotions/comparisons to fail to do the right thing
> Branch: perl
> ! sv.c
It's not obvious to me, either- but I suppose any of these could have done it.
The install date on my 5.6 is 2000/03/27.
Thanks!
--
Joe Schaefer
------------------------------
Date: Fri, 03 Nov 2000 17:50:32 GMT
From: chronofish@my-deja.com
Subject: Re: CGI slow, command line fast ?
Message-Id: <8tutt5$l0o$1@nnrp1.deja.com>
The difference that you see is probably because when going through the
CGI you are making a message request, which takes time, forking off a
process, which takes time, gathering processes output, which takes
time, and sending a messag back to the browser, which takes time.
I'll go out on a limb here and suggest that if you were to concatenate
to a buffer rather than printing out as you parse, and print the buffer
after your processing was complete, your time stamps would show a huge
improvement (though I can not quarentee that the response time to the
user will be any better).
Good luck!
- Christopher
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
www.chronofish.com
In article <8tpj7j$6jg$1@nnrp1.deja.com>,
mgrabens@popd.isinet.com wrote:
> I am having a odd problem. I wrote a simple little subroutine that
uses
> regular expressions to parse a file. When I hit a particularly large
> file it takes the CGI 15-20 seconds to parse it. To look into the
> performance issues, I wrote a command line script that uses the
library
> and parses the same file. The command line version takes between 1.5
and
> 2 seconds (used Time::HiRes).
>
> I have tested the CGI on both apache and Netscape server, same basic
> time results.
>
> Both the CGI and command line are using the same Perl. Run times were
> taking one right after another, so system load may have changed, but
not
> that drastically. Plus the time differences are consistently off by
> roughly the same amount. (ie. 1.5 seconds from the command line, CGI
15
> seconds, 1.9 seconds from the command line, CGI 19 seconds).
>
> It is definately not a decimal problem (though it appears like that).
>
> I have printed out the information as I parse it with a time stamp and
> it shows a natural progression through the file. IOW: the regular
> expressions are not getting into some strange loop. (no visible jumps
in
> seconds between any part of the file, nice and consistant.)
>
> Does the priority level cause this much of a difference ?
>
> Any other ideas ?
>
> I am stumped...
>
> Thanks,
> Mike
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 03 Nov 2000 10:46:28 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Communicating with a child process
Message-Id: <m3r94txau3.fsf@dhcp11-177.support.tivoli.com>
Tim Conrow <tim@ipac.caltech.edu> writes:
> Why not make "(do something)" do this:
>
> print "<<<RESET COUNTER>>>\n";
>
> and add a line like this to the child:
>
> $line = 0 if /^<<<RESET COUNTER>>>$/;
To be completely robust, define a command specifier and then quote it
somehow if it appears in the data. Using Tim's suggested syntax is
fine, I would just add something like:
$_ = "<<<DATA>>>" . $_ if /^<<</;
and then in the child:
$command = $1 if /^<<<([^>]*)>>>/;
# then process various commands
$line = 0 if $command eq "RESET COUNTER";
$_ = s/^<<<DATA>>>// if $command eq "DATA";
This way, you have a clean syntax for passing arbitrary commands to
the child as your need grows.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 3 Nov 2000 09:07:42 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Continuous file modification age monitor
Message-Id: <3a02e2ce$1@cs.colorado.edu>
Don't post the same thing twice.
Learn to indent.
--tom
------------------------------
Date: Fri, 03 Nov 2000 18:08:30 GMT
From: wildhorses@my-deja.com
Subject: does anyone know if this will work?
Message-Id: <8tuuun$m2v$1@nnrp1.deja.com>
We want to test to see if our sql data base is working or not. Does
this ($Conn->Open( "username", "password", "databasename" )) return
true or false if used as posted below?
<%@ LANGUAGE = PerlScript %>
<%
$Conn = $Server->CreateObject("ADODB.Connection");
if ($Conn->Open( "username", "password", "databasename" )){
$Response->Write("SUCCESS");
}
else{
$Response->Write("UNSUCCESSFUL");
}
$Conn->Disconnect();
%>
<html>
<meta name="Microsoft Border" content="none, default"> <body>
</body>
</html>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 03 Nov 2000 17:22:39 GMT
From: jkipp@mbna.com
Subject: Re: Duplicate lInes in File count and del routine
Message-Id: <8tus8k$jfc$1@nnrp1.deja.com>
> I hope you'll permit a few comments not directly related to your
stated problem.
>
Tim
I appreciate your comments and suggestions. I am somewhat new to Perl
and programming (except for shell scripting) and I need all of the help
constructive criticism I can get. Please feel free to comment all you
want during this thread.
> > ---------------
> > elsif (defined($opts{f} && $opts{l})) {
> > my $file = $opts{f};
> > my $log = $opts{l};
> > pfile_log(\$file, \$log);
>
> Why are you passing references? No problem, I guess, just wondering.
There is a routine that I left out that uses the ref function to
determine if a scalar or array argument is used to call it. I may be
changing that part anyway.
> > the file is passed to another routine that parses the file and and
pairs
> > the IP adr with a hostname
> > ---------------
> > sub pfile_log {
> > my ($file, $log) = @_;
> >
> > open(FILE, "$$file") or die "Can't open $$file:$!" if -e
$$file;
>
> So what happens if the file doesn't exist? The following lines roll
relentlessly
> on, producing garbage. Perhaps you meant something like
>
> return if ! -e $$file;
> open(FILE, "$$file") or die ...
Yes, I agree. no need for the if -e file test. I will remove it.
>
> > my @file = <FILE>;
> > close FILE or die "Can't close $$file:$!";
>
> I admire your zealousness about including the 'or die' clause on the
close, but
> really the test you want to perform is on @file, unless it's allowed
to be
> empty;
Would it be better to leave out the die statment all together?
>
> warn("File $$file empty.\n"),return unless @file;
Can you explain the above line. I am not good with returns :-)
> > open(LOG, ">$$log") or die "Can't open $$log for
writing:$!";
> > foreach (@file) {
>
> Why slurp in the whole file? Why not use a
>
> while(<FILE>) {
>
> structure. Then you don't ever have to care about how big the file
gets.
>
I am not quite sure how to do this. Can you elaborate?
I gave it a try. (I included the revised script,only the important
parts,at the end of the post)
> > chomp;
> > if (/( \d{1,3} \. \d{1,3} \. \d{1,3} \. \d
{1,3} )/gx){
>
> What's the 'g' there for?
It's gone now :-)
> >
> > my $name = gethostbyaddr(inet_aton($1), AF_INET);
> > print LOG "$name => ",$1, "\n";
> > } else {
> > next;
> > }
> > next;
>
> Perhaps I'm being overly picky, but the 'next's aren't necessary.
>
Not being overly picky at all, the less code the better. I do see how
the next are redundant.
> > Here is what we need it to now do.
> > Read each line in the result log file(ip/hostname combo) if we find
a
> > dup line start counter at 2 and delete the dup line
> > if find again add 1 to count
> > delete the dup line
> > do until EOF
> > print non dup lines just as "Ip -> Host"
> > print dup lines "ip -> host" x "times"
>
> Here's a solution to use if you know the list won't get too big
(untested):
>
> my @table;
> my %counter;
> while(<LOG>) {
> my ($name,$ip) = split /\s*=>\s*/;
> push @table,[$name,$ip] if ! $counter{$name}++;
> }
>
> for (@table) {
> print "$ip -> $host".
> ($counter{$name} > 1 ? " x $counter{$name}" : "").
> "\n";
> }
>
> Is that what you meant? Or did you mean
>
> print "$ip -> $host\n"x$counter{$name};
>
either one works.
Here is the script revised after your suggestions. I will not be able
to test until tonight. I will also copy your private email if OK.
Thanks for the help
Jim
---------------------
getopts('hl:i:f:',\%opts);
} elsif (defined($opts{f} && $opts{l})) {
my $file = $opts{f};
my $log = $opts{l};
pfile_log(\$file, \$log);
} elsif (defined($opts{h})) { usage(); }
else { usage();
}
sub pfile_log {
my @table;
my %counter;
my ($file, $log) = @_;
open(FILE, "$$file") or die "Can't open $$file:$!";
#my @file = <FILE>;
while (<FILE>) {
open(LOG, ">$$log") or die "Can't open $$log: $!";
foreach (@file) {
chomp;
if (/( \d{1,3} \. \d{1,3} \. \d{1,3} \. \d
{1,3} )/x) {
my $name = gethostbyaddr(inet_aton($1),
AF_INET);
## IS THIS CORRECT?
#print LOG "$name => ",$1, "\n";
while(<LOG>) {
my ($name,$ip) = split /\s*=>\s*/;
push @table,[$name,$ip] if !
$counter{$name}++;
}
for (@table) {
print "$ip -> $host".
($counter{$name} > 1 ? " x
$counter{$name}" : "")."\n";
}
}
close LOG or die "Can't close $$log:$!";
}
close FILE or warn("File $$file empty.\n"),return unless @file;
}
while(<LOG>) {
my ($name,$ip) = split /\s*=>\s*/;
push @table,[$name,$ip] if ! $counter{$name}++;
}
for (@table) {
print "$ip -> $host".
($counter{$name} > 1 ? " x $counter{$name}" : "").
"\n";
}
--------------------
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 03 Nov 2000 18:22:55 GMT
From: jkipp@mbna.com
Subject: Re: Duplicate lInes in File count and del routine
Message-Id: <8tuvpm$mqi$1@nnrp1.deja.com>
> > print non dup lines just as "Ip -> Host"
>
> Do you really mean to reverse the order? The previous code (which I
> did not include) printed "Host -> IP".
Yes, you are correct.
>
> > print dup lines "ip -> host" x "times"
>
> my %line_count;
> my @lines; # only needed if order matters
>
> open FILE, $file or die "Could not open $file, $!";
> while (<FILE>) {
> chomp;
> $line_count{$_}++;
> push(@lines, $_); # I'm saving the order here.
> }
> close FILE;
>
> foreach (@lines) { # If order isn't important, use "keys %line"
> print;
> print " $line_count{$_} times" if $line_count{$_} > 1;
> print "\n";
> }
The order is not important. I am not quite sure I know what you are
doing here or how to implement into my routine.
Thanks
Jim
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 03 Nov 2000 17:05:08 GMT
From: "Ben Kennedy" <bkennedy99@home.com>
Subject: Re: efficiently passing objects
Message-Id: <8fCM5.88512$td5.13306362@news1.rdc2.pa.home.com>
"Dale Emmons" <dale@emmons.dontspamme.com> wrote in message
news:t01996nriifu78@corp.supernews.com...
> I'm curious, is code like this efficient? Or is there a better way to do
it?
You need to narrow this down to a smaller chunk or smaller chunks of code
---Ben Kennedy
------------------------------
Date: Fri, 3 Nov 2000 16:42:02 -0000
From: "Lee Denny" <lee@areality.co.uk>
Subject: Freelance Programmer Neede - Good Money
Message-Id: <973269170.28814.1.nnrp-10.c2dee5ab@news.demon.co.uk>
Sorry if this is the wrong group, but we need an urgent quote on the
attached specification.
Thanks in advance
------------------------------
Date: Fri, 03 Nov 2000 17:40:06 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Freelance Programmer Neede - Good Money
Message-Id: <8tutd9$cpm$1@news.mch.sbs.de>
In article <973269170.28814.1.nnrp-10.c2dee5ab@news.demon.co.uk>, "Lee Denny" <lee@areality.co.uk> wrote:
>Sorry if this is the wrong group, but we need an urgent quote on the
>attached specification.
>Thanks in advance
Hmmm, that looks like it'll require at least 3 months of analysis,
7 months of development and another 2 months for testing.
Are you sure you want to do that ?
Michel.
------------------------------
Date: 3 Nov 2000 17:47:22 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: Freelance Programmer Neede - Good Money
Message-Id: <slrn905uha.rre.dha@panix2.panix.com>
On Fri, 3 Nov 2000 16:42:02 -0000, Lee Denny <lee@areality.co.uk> wrote:
>Sorry if this is the wrong group
Well...
You have posted a job posting or a resume in a technical group.
Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.
Had you read and understood the Usenet user manual posted frequently
to "news.announce.newusers", you might have already known this. :) (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Please do not explain your posting by saying "but I saw other job
postings here". Just because one person jumps off a bridge, doesn't
mean everyone does. Those postings are also in error, and I've
probably already notified them as well.
If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.
There is a Perl Jobs Announce list that may be more helpful to you. See
<http://www.pm.org/mailing_lists.shtml> for details.
Yours for a better usenet,
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
There's more than one way to skin a cat, and I happen to know that's
factually true. - Mayor Wilkins
------------------------------
Date: 03 Nov 2000 09:48:02 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Getting Perl to wait for another Program
Message-Id: <m34s1pys3x.fsf@dhcp11-177.support.tivoli.com>
sty2999@my-deja.com writes:
> Is there any way to improve upon this? If possible, I would like to
> retain a similar approach to what I am using. I don't want to get into
> complex areas like OLE, and I would like the solution to be portable
> (not just Windows--even though currently we are using VB).
I'm not familiar with VB, so I do not know how feasible this is, but
it really sounds like you should just have a pipe between the two
processes. In Perl, you would simply start the second process via:
open PROC2, "|proc2" or die;
Then, the first process could just write the data to the PROC2
filehandle and proc2 would read from STDIN. This would be a blocking
read, so it would automatically wait for the next chunk of data. You
would almost certainly want to disable buffering for the PROC2
filehandle.
> Is there some way to get the perl process to idle for a short peroid
> during the loop, so it doesn't suck up all the CPU cycles? What I
> would really like is something like the Windows timer, where you can
> have it check every 10th of a second or so. I believe Perl has some
> sort of "wait" function but I think it only works in whole
> seconds...which is way to long a period.
Search the FAQ for "sleep" and you should find an answer for this
(select() being the normal answer).
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 01 Nov 2000 15:01:00 -0500
From: Jeff Boes <jboes@eomonitor.com>
Subject: Re: How do I get the html source code from a page on another server
Message-Id: <3a030a9e$0$35013$44a10c7e@news.net-link.net>
MNJP wrote:
>
> The fast and cheap way to do it is
>
> $source = `lynx -source http://www.blah.com/dir/filename.ext`;
>
> "Peter Naimoli" <pnaimoli@rochester.rr.com> wrote in message
> news:THKL5.115330$JS3.17855879@typhoon.nyroc.rr.com...
> > I am writing a script to analyze meta tags in html. But i don't know how
> i
> > could make my perl script get the html source from a given page, usually
> on
> > a different server.
> > If anyone could show me how to do this, i would be very grateful.
> > Pete
> >
> >
... which works nicely on any machine which happens to have lynx
installed. Otherwise, it's broken.
The more portable way is...
use LWP::Simple;
$source = get(q!http://www.blah.com/dir/filename.ext!);
--
Jeff Boes <jboes@eoexchange.com> Tel: (616) 381-9889 x.18
Sr. Software Engineer, EoExchange, Inc. http://www.eoexchange.com/
Search, Monitor, Notify. http://www.eomonitor.com/
------------------------------
Date: Wed, 01 Nov 2000 14:52:40 -0500
From: Jeff Boes <jboes@eomonitor.com>
Subject: Re: INTERACTIVE DEBUGGER !!??
Message-Id: <3a030a9d$0$35013$44a10c7e@news.net-link.net>
Ted Zlatanov wrote:
>
> It would be unfair to omit the Devel::Ptkdb module, which is very nice
> for beginners. It is on CPAN (http://search.cpan.org). I have found
> it useful many times.
>
BTW: this is found as Devel::ptkdb (note case), in case anyone's trying
to install it from the CPAN shell.
--
Jeff Boes <jboes@eoexchange.com> Tel: (616) 381-9889 x.18
Sr. Software Engineer, EoExchange, Inc. http://www.eoexchange.com/
Search, Monitor, Notify. http://www.eomonitor.com/
------------------------------
Date: 03 Nov 2000 10:30:58 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Need suggestions on optimization
Message-Id: <m3zojhxbjx.fsf@dhcp11-177.support.tivoli.com>
David Coppit <newspost@coppit.org> writes:
> sub ReadEmail
> {
> my $fileHandle = shift;
>
> return undef if $READ_BUFFER eq '' && eof($fileHandle);
>
> while (1)
> {
> # pos = 1 to avoid matching first email in buffer
> pos($READ_BUFFER) = 1;
> while ($READ_BUFFER =~ /^From\s.*\d:\d+:\d.* \d{4}/igm)
Do you really need to match all those digits? Does the file have
other lines that start with "From " that are not real From lines?
Right here I start to get the feeling that you could define $/ as
"\nFrom " and process a message at a time. The possibility of
included messages would still need to be handled (assuming that they
also start with "From "), but that shouldn't be a problem. I expect
you would get an appreciable performance improvement from this change
alone.
> {
> my $email = $`;
> my $from_line = $&;
> my $rest = $';
The inclusion of these special variables in a script causes *all*
regexes in the script to save this information, making them all
slower. I do not know how significant the impact is (probably minimal
in this case), but the above recommendation would also eliminate the
need for them.
> # Avoid false positives from included messages. Reverse the email before
> # searching (for efficiency).
> my $reversed = reverse $email;
> if ($reversed !~ /^\n*[^\n]*?----- egasseM dedulcnI nigeB -----\n/i)
> {
> $READ_BUFFER = $from_line . $rest;
> return $email;
> }
> }
>
> if (eof $fileHandle)
> {
> my $email = $READ_BUFFER;
> $READ_BUFFER = '';
> return $email;
> }
> else
> {
> read($fileHandle,$block,$READ_SIZE);
> $READ_BUFFER .= $block
> }
> }
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 3 Nov 2000 18:35:25 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Need suggestions on optimization
Message-Id: <eli$0011031251@qz.little-neck.ny.us>
In comp.lang.perl.misc, David Coppit <newspost@coppit.org> wrote:
> On Thu, 2 Nov 2000, brian d foy wrote:
> > > 4021 14.48674 14.30000 $matchesBody = ($body_buffer =~
> > if that is taking up the most time, you might delve into
> > Mastering Regular Expressions to see if you can optimize
> > the regular expression. :)
> Unfortunately, I already have over $100 in Perl books, and I'm a poor
> graduate student who can't afford another. :( Here's the situation, in
> case anyone has ideas:
For what it is worth: optimizing regular expressions in Perl is
highly version specific. 'use Benchmark' and a bunch of ways of
doing it will help you figure out what is fast and what isn't.
> sub ReadEmail
> {
> my $fileHandle = shift;
>
> return undef if $READ_BUFFER eq '' && eof($fileHandle);
>
> while (1)
> {
> # pos = 1 to avoid matching first email in buffer
> pos($READ_BUFFER) = 1;
> while ($READ_BUFFER =~ /^From\s.*\d:\d+:\d.* \d{4}/igm)
> {
> my $email = $`;
> my $from_line = $&;
> my $rest = $';
This looks sucky to me. You slow down all REs in the program
when you use $`, $& or $'. It would probably be faster to
loop over lines in the message, coping into $email until you
match a from line. (If you can set the input record seperator
to "\nFrom " you could probably speed things up with that.
If your mailer does not escape such lines, you could be bitten
by bogus ones, though.)
> # Avoid false positives from included messages. Reverse the email before
> # searching (for efficiency).
> my $reversed = reverse $email;
> if ($reversed !~ /^\n*[^\n]*?----- egasseM dedulcnI nigeB -----\n/i)
> {
> $READ_BUFFER = $from_line . $rest;
> return $email;
> }
> }
How about using rindex to search for "Begin ..." from the end
of the message?
> if (eof $fileHandle)
> {
> my $email = $READ_BUFFER;
> $READ_BUFFER = '';
> return $email;
> }
> else
> {
> read($fileHandle,$block,$READ_SIZE);
> $READ_BUFFER .= $block
> }
> }
>
> $READ_BUFFER has an email at the beginning, and I'm trying to find the
> next email (avoiding false positives resulting from headers which
> follow "Begin Included Message").
What happens if either the from line or the included message line
falls on an block boundary?
If you use the input record seperator trick, you can just check
for "Begin Included Message" at the end of the mail.
> If I don't find a valid match, then I need to read a chunk from the
> file, append it to the $READ_BUFFER, and try again.
>
> Some things I noticed/tried:
> - reversing the email before looking for text at the end of it is much
> faster
What about reading line by line and searching for "Original Message"
/ "From ..." as you go along. If for some reason you can't or
don't want to use the built-in input buffering, your buffer stuff
could be used, but you should be using 'sysread' instead of 'read'.
> - I tried to avoid having to re-match portions of the buffer that were
> already searched by setting pos = old length - 80
> - I tried pre-extending the buffer when it got small in order to help
> the match work on the first try.
> - I tried $1,$2,$3 instead of $` $& $'
> - I thought of splitting into an array to avoid $` or $1 business, but
> that seems like it would add a lot more steps and therefore time
If you have the memory, go for it, at least for benchmarking.
Elijah
------
did not see significant improvement from reverse, in his benchmarking
------------------------------
Date: Fri, 3 Nov 2000 15:55:12 -0000
From: "mark" <markscott@barclays.net>
Subject: Re: Onload right or wrong
Message-Id: <3a02e01b@news.jakinternet.co.uk>
Thanks I needed that, thanks for the quick reply, mark
arse <xerxes_2k@my-deja.com> wrote in message
news:8tufog$81b$1@nnrp1.deja.com...
>
>
> > just stick that any where in the script
>
> when i say script i mean html file.
>
> --
> [][][]{}{}~~';:.<<//?|1¬!"£$$%^^&*(())__+/*+
> oooh random characters i must be coool!
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Fri, 3 Nov 2000 18:17:41 -0000
From: Rosemary I H Powell <rosie@dozyrosy.plus.com>
Subject: Re: Perl Question
Message-Id: <MPG.146d118717bec69e989708@usenet.plus.net>
In article <ant020100339fNdQ@oakseed.demon.co.uk> dated Thu, 2 Nov 2000
01:20:00 +0000, our revered colleague James Taylor
(james@NOSPAM.demon.co.uk) was so kind as to advise ...
> It's spooky to think that a choice of subject line could render my
> post invisible to a number of knowledgeable people. It feels like an
> indiscriminate censorship, or one might even go as far as to call it
> unfair discrimination. Although I have to admit I'm secretly tempted
> to discriminate too. ;-)
>
It's the CORRECT choice of subject that will attract them to your post.
Make it interesting and relevant and you will (most probably) get the
audience your require; they don't have time or the desire to read ALL the
stuff posted here, and why should they? - Do you?? :-)
Rosemary
--
----------------------------------------------------------------
| Rosemary I.H.Powell EMail: Home: rosie@dozyrosy.plus.com |
| Work: r.i.h.powell@rl.ac.uk |
| http://NeedleworkSamplers.com/ |
| http://www.CavalierKingCharles.com/ |
----------------------------------------------------------------
------------------------------
Date: Fri, 03 Nov 2000 18:54:32 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Postprocessing output to a file
Message-Id: <46260t01m59qfd19f83sjdskl1ggbvmlp5@4ax.com>
Ren Maddox wrote:
>Are you actually having a problem with it or just presenting your
>solution?
Both. I was facing this problem, which doesn't seem obvious. My code was
the *first* thing I tried. IMO, it's kinda neat. I think it's the best
approach. The only thing that could really stand in the way, if it would
turn out to be *really* slow. I haven't benchmarked it yet. I should. I
will.
But I'm not sure if there are any problems with it. I'm interested in
any feedback. Oh, I can alrready think of one problem: you'll get a
warning if $\ is not defined.
>> Here's what I did (note that I use "printf" because it DOESN'T append $\
>> at the end of what it prints):
>
>I notice that you still use "\n", which is still going to put in the
>OS-specific line ending unless you binmode() the filehandle, which you
>don't seem to do.
Oh, yes. That's a good idea. In this example of uppercasing, "\n" still
represents the native version of line end, just like I wanted. In the
case of turning Windows text into Mac text, "n" needs to be turned into
"\r". That's why in my code, $\ included in the string argument to the
callback function, which does the actual conversion. And no, not
applying binmode still doesn't hurt. But what if you want to convert
into Unix text?
Well, adding a binmode parameter to my tieing function, which opens the
file, is an idea.
--
Bart.
------------------------------
Date: Fri, 3 Nov 2000 16:04:03 -0000
From: Aidan Dunphy <Aidan.Dunphy@orchard-systems.co.uk>
Subject: Problems using MIME::Lite and SMTP
Message-Id: <99ED1629CF36D3118B4A00A0C9837CF37C71F8@swan>
I'm trying to use MIME::Lite to send mail via SMTP from an NT platform.
Following the instructions that come with Lite, the script looks like:
#!perl -w
use MIME::Lite;
MIME::Lite->send('smtp', "{name of SMTP server}", Timeout=>60);
$msg = MIME::Lite->new(
From => '{senders internet email address}',
To => '{recipients internet email
address}',
Cc => '',
Subject => 'Test SMTP message sent using Perl',
Type => 'multipart/mixed'
);
$msg->attach(Data=>'Some body text',
Type=>"TEXT");
$msg->attach(Path=>'d:\wip\attachment.txt',
);
$msg->send;
This works fine UNLESS the recipient's email address begins with "s", in
which case the message is bounced by Exchange because of an unknown
recipient. The email address it quotes as being unknown has lost the
initial "s" - e.g. sending to simon.smith@... would be bounced because
"imon.smith@..." is unknown. Has this anything to do with the fact that
I get the following warnings when executing the script?
Unrecognised escape \s passed through at (eval 2) line 11.
Unrecognised escape \s passed through at (eval 2) line 11.
Unrecognised escape \s passed through at (eval 2) line 11.
Any help would be much appreciated.
------------------------------
Date: Fri, 03 Nov 2000 18:26:34 GMT
From: "LostShade" <lostshade@home.com>
Subject: Timers?
Message-Id: <urDM5.62566$RP.12615748@news1.rdc1.md.home.com>
Hello,
What seems to be a very common theme to this board "I new to Perl"
I have spent the last year or so making an online multi-player game.
Turned out very nice however I cut out a large potential audiance by it
being only supported in windows. Not to mention the unbelievable number of
people who have difficulty understanding they need certain support files...
such as... "If you dont have DirectX7 installed download it here before
running the game..." Sorry a little frustrating, last week I got 10 emails
in one day saying they tried my game but got this error....humph So I
started looking into to other ways of doing this....
Since last week, I have studyed and found Perl is quite capable of doing
everything needed.... with some slight adjustments to my graphical interface
I think it could work quite well....
Which brings me to my question. So far the only thing I haven't found is a
way to really tie multiple people together. Looking at dozens of chat
scripts I found some very lame possibilities. All of which have negative
effects I dont like.
I saw mention of time() and times(). $^T in an earlyer post all of which
in my research so far I have found no mention of. Im kinda asking for
perhaps a little more information on these.
If upto 10 players do things there actions are saved to X file. What I would
like to do is every second have a sub routine open and load the new data and
react to it... easy enough, and sounds like it would work fine... but what I
can't figure out is why these chat rooms dont do this... so in effect how
would you make a timer?
The X file would likely be less then 1000 Bytes at all times. I know I have
to flock the file when someone is going to write to it, should the same
thing need to be done if the users are just reading? I would expect upto 10
reads and upto 2 read then write routines per second... would this result in
a backup of people just waiting to read the file?
Also another consideration... when I ask to open the file, does the script
stop dead and wait for the servers responce, or could I count on everything
else flowing smothly(if someone clicked a button, would the action for the
button be carried out or would it wait until it got the responce?).
Actually, here is a possibility.... if the remainder of the script
continues to run fine... what about the timer and the subroutine that makes
the request...if the timer continues to countdown would it submit additional
requests each second? more to the point would it get a responce from the
server for each of these requests. So in effect even with server lag you
could expect to eventuallu get a responce for every second?
One final possibility if the remaineder of the program continues to run and
only the routine waiting on a responce would be paused. would perhaps a loop
work... I haven't found an equivilent to a "do while" loop either. I presume
something of that natures does exist. could you just lock it in a loop the
only real action would be to load the file and update that info.
Ok sorry kinda went a little off course there. I would appreaciate any
suggestions or comments on how you think I could get this thing loading
constantly. Oh, and some info on the time() thing. Would be nice to know
even if it couldn't be used here...
Thanks in advance,
~Lostshade
...in the end we all die...
------------------------------
Date: 03 Nov 2000 10:37:14 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: values of strings
Message-Id: <m3vgu5xb9h.fsf@dhcp11-177.support.tivoli.com>
Josef Moellers <josef.moellers@fujitsu-siemens.com> writes:
> Danny Hendrickx wrote:
> >
> > Hello,
> >
> > I just split up a string in its individual characters. Now I would like
> > to print the hex-value of each character of that string, (sort of like
> > printf("%X",$a) in C, where $a would contain a character), but I can't
> > find the perl way to do this. Can anyone help me please.
>
> ord() is your friend.
Here is another method that also supplants your split:
printf "%X", $_ for unpack "c*", $string;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 03 Nov 2000 17:43:52 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <sPCM5.915$if4.173477@news.uswest.net>
Bart Lateur <bart.lateur@skynet.be> elucidates:
> Jerome O'Neil wrote:
>
>>Now, Grasshopper, you're journey truley begins...
>
> I wonder: is this a language error that a spell checker can catch?
Rats.
--
"Civilization rests on two things: the discovery that fermentation
produces alcohol, and the voluntary ability to inhibit defecation.
And I put it to you, where would this splendid civilization be without
both?" --Robertson Davies "The Rebel Angels"
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4805
**************************************