[17947] in Perl-Users-Digest
Perl-Users Digest, Issue: 107 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 20 18:06:59 2001
Date: Sat, 20 Jan 2001 15: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: <980031909-v10-i107@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 20 Jan 2001 Volume: 10 Number: 107
Today's topics:
Re: calling a script within a script??? nobull@mail.com
Re: CGI Problem (Garry Williams)
Re: CGI Timeout - Avoiding nobull@mail.com
Re: Database connection pool with Perl Object Environme <brannon@lnc.usc.edu>
Re: Directory Last Modified <sdmeisner@SPAMGUARDyahoo.com>
Re: Directory Last Modified gnari@my-deja.com
Re: Directory Last Modified (Tad McClellan)
Re: FAQ 9.15: How do I decode a CGI form? <joehecht@code4sale.com>
Re: FAQ 9.15: How do I decode a CGI form? <joehecht@code4sale.com>
Re: GD.pm/ImageMagick - Any thing better? <smullett@omeninc.com>
help needed with parsing a HTML form <whitetiger@pinc.com>
How to debug memory leak in a perl script? (Stan Brown)
Re: Is there a standard, current Perl for Win32 (withou (Cameron Laird)
Newbie question <ewsr1@home.com>
Re: NEWBIE: need help with search spider/crawler (Heikki Kortti)
Re: NEWBIE: need help with search spider/crawler <flavell@mail.cern.ch>
Re: overhead on filehandle opening/closing (Garry Williams)
Re: percentages, how? <godzilla@stomp.stomp.tokyo>
Re: Perl - Bytecode, Compile to C, Perl2EXE <dparis@w3works.com>
Re: Powerful Technique 3606 (Tad McClellan)
Q: Select-based read, parent and child <bas@integrators.demon.nl>
Re: Random Numbers with a Twist <joe+usenet@sunstarsys.com>
redirect and cookie (+domain) does not work! <jccann@catholic.org>
Re: Suppressing stderr on `` commands (Garry Williams)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Jan 2001 22:46:09 +0000
From: nobull@mail.com
Subject: Re: calling a script within a script???
Message-Id: <u9k87p3kr2.fsf@wcl-l.bham.ac.uk>
"Sand" <fsburrow@georgefox.edu> writes:
> Dumb question I know, but....
Do you know this because you've read some of the previous threads
where this question was asked?
It is asked at least once a week.
> Does anyone know how to call a cgi script within another script??
The way to call a CGI script is to issue an HTTP request to a web
server. The way to issue an HTTP request from within a Perl program
is LWP.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 20 Jan 2001 19:19:03 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: CGI Problem
Message-Id: <Hwla6.316$tg4.10297@eagle.america.net>
On Fri, 19 Jan 2001 23:52:47 GMT, Dogansmoobs
<dogansmoobs@softhome.net> wrote:
># First open the message counter and get the number of messages already there
># Check for a lockfile and open it (lock the counter)
>while (-e "lockfile")
>{ sleep(1); }
>open (LOCKFILE, ">lockfile");
This is a classic race condition. You should read the FAQ about how
to lock a file (perlfaq5: "How can I lock a file?") and the more
directly appropriate entry:
perlfaq5: "Why can't I just open(FH, ">file.lock")?"
It mentions *exactly* the code you're using and explains why it won't
work correctly.
The other problem with using the existence of a file as a lock (even
when it's done correctly), is that the program then has to find some
way to recover from a previous process not deleting the lock file
because of some unrecoverable failure. All cooperating processes have
to have lock expiration logic to recover from this possibility.
># Open the counter file, read the number, increment and write it back
>if (open (COUNTERFILE, "msg_counter")) then ($numMsg = <COUNTERFILE>;)
>else ($numMsg = 0;)
>$numMsg++;
>close (COUNTERFILE);
>
>open (COUNTERFILE, ">msg_counter");
>print (COUNTERFILE "$numMsg");
>close (COUNTERFILE);
>
># Close the lockfile and delete it
>close (LOCKFILE);
>unlink ("lockfile");
Oh, you want to increment a counter. Hmmm. There's an explanation of
how to this properly in the perlopentut manual page. Look under the
"File Locking" section. The technique does not use an auxiliary lock
file and uses flock() so that cooperating processes don't have to
recover from "stale" locks.
--
Garry Williams
------------------------------
Date: 20 Jan 2001 22:33:04 +0000
From: nobull@mail.com
Subject: Re: CGI Timeout - Avoiding
Message-Id: <u9ofx13lcv.fsf@wcl-l.bham.ac.uk>
"Tamer" <tamer@nospam.yahoo.co.uk> writes:
> Newsgroups: comp.lang.perl.misc
This is a Perl newsgroup.
> I wonder if the server has been set up with a very short timeout as this
> occurs after 10 seconds or less.
> Is there anyway I can avoid this error , increase the timeout setting , or
> at least trap the error?
This is a question about web server configuration - unrelated in any
way to Perl.
Even if it were acceptable to answer such questions here (it isn't) we
couldn't as we don't know which web server you are talking about.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 20 Jan 2001 20:28:17 GMT
From: Terrence Brannon <brannon@lnc.usc.edu>
Subject: Re: Database connection pool with Perl Object Environment?
Message-Id: <lbelxy7yu9.fsf@lnc.usc.edu>
Carfield Yim <carfield@my-deja.com> writes:
> Can I implement a database connection pool with Perl Object Environment
> (POE)?? Seen to me that it can, as it can implement any kind of service, it
> is right?
MSCHWERN has already created a database connection pool.
http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search?join=and;arrange=file;download=auto;stem=no;case=clike;site=ftp.funet.fi;age=;distinfo=1043
BTW, Perl.com has a beginner introduction to POE just out.
>
>
> Sent via Deja.com
> http://www.deja.com/
--
Terrence Brannon
Carter's Compass...
I know I'm on the right track when by deleting code I'm adding
functionality.
------------------------------
Date: Sat, 20 Jan 2001 19:34:12 GMT
From: "Sean Meisner" <sdmeisner@SPAMGUARDyahoo.com>
Subject: Re: Directory Last Modified
Message-Id: <UKla6.121$215.25610@sapphire.mtt.net>
Just treat the directory as you would a non-directory file..
$modtime = (localtime((stat($dir))[9]));
will give you the last modified time for $dir, assuming $dir contains
either: the full path of the directory in a string, or a FILEHANDLE
opened on the directory file, not a DIRHANDLE.. don't use stat _
unless you've just done a (-d $dir) or something of the sort..
BUCK NAKED1 <dennis100@webtv.net> wrote in message
news:10842-3A69DACF-24@storefull-244.iap.bryant.webtv.net...
> How do you get the Last Modified (or if-modified-since) time from a
> directory? I don't want to use any more modules than the LWP::Simple and
> CGI (':standard) that I'm already using. I've looked for 2 days and
> can't find any info on how to do this. Here is what I'm trying.
>
> while (readdir <$dir*>) { $modtime = (localtime((stat _)[9]));
> print "Age of directory $dir is $modtime<BR>" } ;
>
> My final goal is to remove a directory after a certain amount of time.
>
> Thanks,
> Dennis
>
------------------------------
Date: Sat, 20 Jan 2001 19:41:16 GMT
From: gnari@my-deja.com
Subject: Re: Directory Last Modified
Message-Id: <94cpkr$bh$1@nnrp1.deja.com>
In article <10842-3A69DACF-24@storefull-244.iap.bryant.webtv.net>,
dennis100@webtv.net (BUCK NAKED1) wrote:
> How do you get the Last Modified (or if-modified-since) time from a
> directory? I don't want to use any more modules than the LWP::Simple
and
> CGI (':standard) that I'm already using. I've looked for 2 days and
> can't find any info on how to do this. Here is what I'm trying.
>
> while (readdir <$dir*>) { $modtime = (localtime((stat _)[9]));
> print "Age of directory $dir is $modtime<BR>" } ;
>
have you tried -C ?
my $age=-C $dir;
print "Age of directory $dir is $age\n";
the file tests can be handy and are simple to use
see perldoc -f -X
for a list of them from
perldoc perlfunc
can also reveal some goodies one was not aware of
gnari
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sat, 20 Jan 2001 19:50:22 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Directory Last Modified
Message-Id: <slrn96jk49.9pf.tadmc@tadmc26.august.net>
BUCK NAKED1 <dennis100@webtv.net> wrote:
>How do you get the Last Modified (or if-modified-since) time from a
>directory?
perldoc -f -M
perldoc -f stat
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 20 Jan 2001 21:56:36 GMT
From: "Joe C. Hecht" <joehecht@code4sale.com>
Subject: Re: FAQ 9.15: How do I decode a CGI form?
Message-Id: <oQna6.1958$db6.224305@paloalto-snr1.gtei.net>
> So you'd both rather keep your own unreviewed bugs, than have a whole
> team of specialist volunteers world-wide working on submitting fixes
> to the author, without any particular effort on your part? Strange.
volunteer specialists??? Where?
You mean those who have already posted (and written books yada yada)
about decoding a CGI form?
uhhh... I think I will pass on that one. No need to deflate egos, else they
might not be able to call themselves volunteer specialists anymore<g>
Seriously, I'm not here to teach :)
I perfer more worthy targets, (well known magizine editors and the like).
Joe
------------------------------
Date: Sat, 20 Jan 2001 21:53:56 GMT
From: "Joe C. Hecht" <joehecht@code4sale.com>
Subject: Re: FAQ 9.15: How do I decode a CGI form?
Message-Id: <UNna6.1955$db6.222529@paloalto-snr1.gtei.net>
"The WebDragon" <nospam@nospam.com> wrote in message
news:94av03$iir$1@216.155.32.222...
> you're dreaming. my "time-elapsed from cold-start knowing NO perl at
> all, to having a finished heavily complex perldsc/perllol-using cgi +
> crontab-run perl script pair" was 3 weeks. I'd never have gotten it as
> far as I did, as fast as I did, without CGI.pm.
>
> Bear in mind there's 'lite' versions as well.
I never said CGI.pm would not get you off the line fast.
All I ever said (or ment to imply) was that the code
examples available (that I have seen) for decoding
CGIforms have all been a bit substandard for what
I do, and a code rework has been necessary.
It is not uncommon for "experts" to write a book,
or review code and the result be less than optimal.
In my area of expertise (Windows API and low level
graphics), I catch experts writing (and posting)
substandard stuff all the time. I have been hired
out to technically review many such experts
books and articles (some being the most well
known names in the industry), and often roll
across code snippets that rank anywhere from
slightly incomplete to total garbage in need of a
complete rewrite. Just because your an industry
expert does not mean you code does not smell.
Just last month I BBQ'd a long time PC Magizine
contributer/editor/bigwig that was posting garbage
code in a graphics forum.
I see another reply here where I am invited to
post better code. Well, I have been posting
freebe code online since 300 baud modems
were state of the art, and for the most part,
I consider myself retired from the job of
giving my code away for free. As my lovely
wife told me, I have been a code whore long
enough, time to start charging [and my work
does not qualify as bargain bin materal suitable
for a kmart blue light special]. That being said,
the fact that I took enough time and effort to
render an opinion is good enough, and it is up
to you to judge if the opinion may have or may
not have merrit.
Joe
------------------------------
Date: Sat, 20 Jan 2001 21:00:16 GMT
From: Sterling <smullett@omeninc.com>
Subject: Re: GD.pm/ImageMagick - Any thing better?
Message-Id: <3A69FC7A.A49CE31E@omeninc.com>
H-
Thanks for your reply.
> > I had looked into using Magick but it really doesn't do all the drawing
> > things that I'll need.
>
> That surprises me a bit. What sort of drawign are you able to do with GD
> that you can't do with Image::Magick? I tend to believe that
> Image::Magick has a lot more than GD. GD is just faster.
Well to be fair I did find the draw feature. The problem I've been
encountering is that it only works when loading images and doing stuff
to those images. I want to create the images from scratch. So far that
hasn't worked out.
Meaning either I'm doing something wrong (most likely) or magick doesn't
like to work/create images from scratch.
For now I'm attempting to do a simple image create(using Image::Magick).
But perhaps this should be taken to some other newsgroup.
Do you know of any?
>
> Oh, I'm forgetting one: You can use the interface to the Gimp. But
> prepare for a steep learning curve, and long searches through
> documentation. if you're not already fluent with the Gimp itself, it's
> hardly useful to even lok at the programmable Perl interface.
Yes, I saw the Gimp interface and was tempted to get into it. Haven't
had good working relations with GIMP. Just me though.
Thoughts, Comments, Anecdotes?
-Sterling
>
> Martien
> --
> Martien Verbruggen |
> Interactive Media Division | In a world without fences, who needs
> Commercial Dynamics Pty. Ltd. | Gates?
> NSW, Australia |
------------------------------
Date: Sat, 20 Jan 2001 12:54:44 -0800
From: "whitetigercat" <whitetiger@pinc.com>
Subject: help needed with parsing a HTML form
Message-Id: <t6juu81higi492@corp.supernews.com>
Hi All,
I am writing a program to retrieve a html page containing a form from another site.
I am using LWP::Simple for this and it works great at getting and storing the page.
Now I need to extract the field names and default values from a form on that page
and store them in an associative array. I haven't done this part of the program yet but
if anyone knows a quick script to do this, it would be appreciated. Also, how do
I do the post (is there a module I should use)?
Thanks in advance,
Shane
------------------------------
Date: 20 Jan 2001 15:11:55 -0500
From: stanb@panix.com (Stan Brown)
Subject: How to debug memory leak in a perl script?
Message-Id: <94creb$sks$1@panix3.panix.com>
I have a failr sized perl script that I am trying to finish up.
This script takes input from a serail port, parses it, and puts the results
in a Postgres DB.
On overnight test runs, with data streaming in at full speed from another
perl script simulator, it appears to continue to grow in memory usage.
Deletting the DB comiits, dose not fix this problem.
Whats the best way to go baout debugng where it's leaking memory?
------------------------------
Date: 20 Jan 2001 14:55:03 -0600
From: claird@starbase.neosoft.com (Cameron Laird)
Subject: Re: Is there a standard, current Perl for Win32 (without ActivePerl?)
Message-Id: <59B92BB870048529.D443236B50E26B3A.41888FDC47D21C19@lp.airnews.net>
In article <0vr64t02htr32oa0makpgmtu0cfseqigf5@4ax.com>,
Philip 'Yes, that's my address' Newton <nospam.newton@gmx.li> wrote:
>On Thu, 21 Dec 2000 16:43:11 -0800, John Nagle <nagle@animats.com> wrote:
>
>> Also, to install ActivePerl, you have to obtain
>> and install a new version of Internet Explorer and an NT service pack,
>> always risky activities.
>
>Not true AFAIK for ActivePerl build 522 (roughly equivalent to 5.005_03 +
>ActiveState patches), which is what I use. (I did have to download something for
>Win98, but it installed as-is on my NT machine at work.)
.
.
.
Me, too: ActivePerl 618 with a WinNT4.0, no service patches,
no Internet Explorer.
--
Cameron Laird <claird@NeoSoft.com>
Business: http://www.Phaseit.net
Personal: http://starbase.neosoft.com/~claird/home.html
------------------------------
Date: Sat, 20 Jan 2001 19:16:05 GMT
From: "bigdawg" <ewsr1@home.com>
Subject: Newbie question
Message-Id: <Vtla6.26372$B6.8112582@news1.rdc1.md.home.com>
Here is what I'd like to do. I am using Activestate on a Win32 system.
I'm also not clear as to which modules may be needed.
1. change to a specific directory
2. read the directory
# using readdir()
3. delete all directories older than $days_old
# using unlink()
4. write output to an existing file to track deleted directories
# using open()
------------------------------
Date: 20 Jan 2001 20:00:07 GMT
From: heikki@nospamhi.is (Heikki Kortti)
Subject: Re: NEWBIE: need help with search spider/crawler
Message-Id: <94cqo7$7kg$1@frettir.rhi.hi.is>
On 17 Jan 2001 00:20:33 GMT, Abigail <abigail@foad.org> wrote:
>\\ In 5.6.0 it treats any more than two consecutive integers separated by
>\\ "." as ascii indices and proceeds to convert these to characters
>\\ then concatenate them.
>
>ASCII only has 128 code points; this constructs works with higher numbers
>as well.
Can we not still start calling the current camel vENQ.ACK.NUL?
--
Heikki Kortti (heikki at hi.is)
------------------------------
Date: Sat, 20 Jan 2001 21:33:59 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: NEWBIE: need help with search spider/crawler
Message-Id: <Pine.LNX.4.30.0101202131540.31643-100000@lxplus003.cern.ch>
On 17 Jan 2001, Abigail wrote:
> ASCII only has 128 code points;
Quite right, of course. So if the bytes prove to have higher values
than 127 and they have been correctly described as ASCII, the
characters must have parity bits ;-)
------------------------------
Date: Sat, 20 Jan 2001 21:05:00 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: overhead on filehandle opening/closing
Message-Id: <04na6.328$tg4.11475@eagle.america.net>
On Fri, 19 Jan 2001 08:51:27 GMT, Anson Parker <ans@_nospam_x64.net>
wrote:
>routine. Currently the daemon opens a filehandle to the log file on startup
>and closes it on shutdown. Given that the daemon could have uptimes
>into the years (hmmm don't think it's quite that robust yet) are there any
>issues with keeping a filehandle open indefinitely?
A well-behaved daemon should accommodate log file truncating/rolling
processes. Typically, the log file is opened on start-up (with
O_CREAT, in case the file doesn't exist) *and* in response to SIGHUP.
That way a crontab entry like this will work:
* * * * 0 mv log_file log_file.bak;kill -HUP `cat pid_file`
Otherwise you will run out of space on the log file partition after
the first year. :-)
--
Garry Williams
------------------------------
Date: Sat, 20 Jan 2001 11:24:47 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: percentages, how?
Message-Id: <3A69E5FF.77834858@stomp.stomp.tokyo>
snef wrote:
> I've got 3 characters: a, b, c in an array (@x)
> Now I want to get one character randomly
> This is easy. Something like $a[rand 3].
> but now i want to add some winning percentages.
> The change to get b must be 80%.
> How can I do this?
You cannot. Your current array displays a percentage
chance of selecting a, b or c as a bit more than
thirty-three-point-three, for each letter.
Populate an array with ten percent letter a, ten
percent letter c and eighty percent, letter b.
My test script below exhibited an eighty-two
percent chance of selecting letter b employing
four test runs of twenty-five iterations each.
Setting aside inherent problems with rand not
being fully random, with thousands of iterations,
this method would exhibit an average eighty
percent chance of selecting letter b.
Simple mathematics.
Godzilla!
--
TEST SCRIPT:
____________
#!/usr/local/bin/perl
print "Content-type: text/plain\n\n";
@Array = qw (a b b b b b b b b c);
print "Test Run One:\n\n";
for ($iteration = 1; $iteration <= 25; $iteration++)
{
$random = $Array[rand(@Array)];
print "$random ";
}
print "\n\nTest Run Two:\n\n";
for ($iteration = 1; $iteration <= 25; $iteration++)
{
$random = $Array[rand(@Array)];
print "$random ";
}
print "\n\nTest Run Three:\n\n";
for ($iteration = 1; $iteration <= 25; $iteration++)
{
$random = $Array[rand(@Array)];
print "$random ";
}
print "\n\nTest Run Four:\n\n";
for ($iteration = 1; $iteration <= 25; $iteration++)
{
$random = $Array[rand(@Array)];
print "$random ";
}
exit;
PRINTED RESULTS:
________________
Test Run One:
b b b a b b b b b c a b a b b b b b a b b b c b b
Test Run Two:
b a a b b a b b b b b b a b b a b b b b b b b b b
Test Run Three:
b b b b b a b b b b b b b a b b b b b a b b b b b
Test Run Four:
b b b b b c b b b b b b b b a b a b b b a b b b b
------------------------------
Date: Sat, 20 Jan 2001 16:35:18 -0500
From: Dave Paris <dparis@w3works.com>
Subject: Re: Perl - Bytecode, Compile to C, Perl2EXE
Message-Id: <3A6A0496.C08AA745@w3works.com>
jgore@home.com wrote:
[...]
> PERL2EXE:
> I could use PERL2EXE and make an executable but my ISP doesn't allow EXE's in CGI-bin.
> It would keep the source secret but people could only run it on their own sever machines.
unless activestate has done some massive changes here, you're not
protecting anything. perl2exe wraps your plaintext code around the
compiled interpreter. anyone with a text editor and two functioning
brain cells can read your code.
-dsp
------------------------------
Date: Sat, 20 Jan 2001 19:50:23 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Powerful Technique 3606
Message-Id: <slrn96jk8i.9pf.tadmc@tadmc26.august.net>
Bart Lateur <bart.lateur@skynet.be> wrote:
>zoycit@email.com wrote:
>
>>pmpmofcqxzgkvsvpobtjfurjdfxnjqmo
>
>This was the most sensible sentence in the whole post. ;-)
>
>Does anybody know how to write a regex that matches this kind of
>neonsense? You can easily recognize it by eye, but... is there really a
>pattern? At least 4 consonants in a row?
^^^^^^^^^^^^^^^^^^^^^
That is discrimination!
Mentioning my name gets it marked as spam?
heh.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 20 Jan 2001 23:51:08 +0100
From: "Bas A. Schulte" <bas@integrators.demon.nl>
Subject: Q: Select-based read, parent and child
Message-Id: <bas-7CDFC7.23510820012001@news.demon.nl>
Hi all,
I'm confused ;) Here's the outline of what I'm trying to do: I'm reading
a command from a blocking input mechanism (could be STDIN, a SysV queue
etc.), that I want to dispatch to a child. Parent and child communicate
through pipes. In the real-world scenario, that child will fork
additional children, with which it will also communicate using pipes.
So, in that child, I want to do select-based reading from an array of
filehandles (select-based cuz' I want to try that in this project ;)).
To experiment, I wrote a script that implements this. The parent simply
reads from STDIN, sends the string off to the child, the child sits in
an endless loop, using select to find out if there's any input to read.
Now, when I test this from my terminal, all works fine: I start the
script, enter a line, hit enter, the parent sends the string, child
returns from the select, reads it, goes back to select. Inputting a 'q'
character ends it; the parent reads the 'q', send it to the child, the
child reads it, and dies. The parent does a waitpid to wait for it's
dying child before it terminates itself.
However, when I try the same using a file as input (perl myscript.pl
<testfile) where the file contains a few lines, it just won't work!
The parent works fine; it reads the commands, send them to the child,
then when it sees EOF, it sends 'q' to the child, ends its read loop,
and does a waitpid on the child.
The child however reads only one or two lines, then never comes back
from the select. It never gets to the final 'q' command.
I assume it's got something to do with buffering. I tried using 'read'
to read in the child (should I be using sysread?); didn't work either.
Or is it that the select returns and the whole buffer is available for
reading while I only read till \n? Should I use a binary protocol
instead, sending a length number first (say 4 bytes), and then the
messages, so that I can read exactly the number of bytes in a message?
What am I missing?
I boiled down the script to what I pasted in below. Sure hope someone
can explain what I'm missing...
Thanks in advance,
Bas.
#!/usr/bin/perl -w
use strict;
use IO::Pipe;
use IO::Select;
sub handler
{
my $from_parent = shift;
my $inSet = IO::Select->new();
$inSet->add($from_parent);
## real world reads from multiple filehandles
while (1) {
## read from all our read filehandles (in this sample only
## the command from our parent)
my @result = IO::Select->select($inSet,undef,undef);
if (scalar(@result) == 0) {
die "fatal error after select: $!\n";
}
my $cmd;
foreach my $handle (@{$result[0]}) {
# Briefly tried 'read' as well. The <> construct probably does
# unexpected buffering (?)
# $handle->read(my $line,5);
my $line = <$handle>;
chomp($line);
if (($cmd) = ($line =~ m/^do\t(.*?)$/)) {
print STDERR "handler]:command from master: --$cmd--\n";
} else {
print STDERR "handler]:unknown command: --$line--\n";
}
}
last if ($cmd eq 'q');
print STDERR "handler]:handling command $cmd\n";
}
print STDERR "handler]:exiting\n";
exit 0;
}
##
## represents an input channel that blocks on a read
##
## returns undef on EOF, or a string, without trailing linefeed
##
sub retrieveElement
{
my $elm = <>;
return unless defined $elm;
chomp($elm);
## give 'm some data if we send an empty line
if (length($elm) == 0) {
$elm = 'abc';
}
return ($elm);
}
sub Main
{
my $to_kid = new IO::Pipe();
my $pid = fork();
die "could not fork: $!\n" unless defined $pid;
if ($pid == 0) {
##
## child
##
$to_kid->reader();
## the kid is a reader on our to_kid pipe end
handler($to_kid);
exit 0; ## not reached
}
##
## parent continues here after forking our child.
## We go on reading from a blocking input mechanism (a SysV queue,
## a PMQ queue etc.)
##
$to_kid->writer();
## we're a writer on the to_kid pipe end
$to_kid->autoflush(1);
## and auto-flush what we send to our kid
while (1) {
my $elm = retrieveElement();
if (not defined $elm) {
$elm = 'q'; ## EOF; send 'quit' to child
}
print STDERR "main]:sending command ($elm)\n";
$to_kid->print("do\t$elm\n");
last if ($elm eq 'q');
}
print STDERR "main]:stop read loop, waiting for child to
finish...\n";
waitpid($pid,0);
print STDERR "main]:child is done, terminating\n";
print STDERR "[main]:exiting normally (our worlds depart here)\n";
}
Main();
------------------------------
Date: 20 Jan 2001 16:13:19 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Random Numbers with a Twist
Message-Id: <m366jasz9s.fsf@mumonkan.sunstarsys.com>
abigail@foad.org (Abigail) writes:
> Rob Greenbank (rob@frii.com) wrote on MMDCXCVIII September MCMXCIII in
> <URL:news:mkfh6tg39vcci60cdles5aq7prfngv7hh9@4ax.com>:
> ~~
> ~~ I see only two ways to avoid the possibility of either multiple
> ~~ attempts or backtracking -- either the size of the "grid" is large
> ~~ enough to insure it won't happen, or you limit the randomness. I
> ~~ probably wouldn't backtrack anyway -- I'd probably just fail it and
> ~~ let the person running the program decide when they've had enough.
>
> Here's an algorithm that will work, and doesn't backtrack (it will
> never get "stuck"):
Unfortunately this algorithm also has a fatal flaw; namely it
assumes that the set of all solutions can be obtained using the
"single-point" transformations that drive the algorithm.
For example, if the problem is to choose a pair of points in a 10x10
grid that are of (Euclidean) distance >= 11, the (disconnected)
solution space consists of pairs of points bunched near opposite
corners of the grid. By starting with one pair of solutions, the
"single-point" transformation algorithm above will miss 50% of the
available solutions (the off-diagonal ones).
However if you stick to boxes as in the OP's case; i.e. in math-speak,
dist (P_1,P_2) = min( |P_1->x - P_2->x|, |P_1->y - P_2->y| ) ,
and assuming you can work out all the relevant conditional
probabilities, *and/or* construct an appropriate _stopping time_
(see below), I believe the algorithm is provably correct (the key
difference is that squares are stackable while circles are not).
Implementing it is an entirely different matter, though :)
>
> Let G be the grid on which the n points have to be placed.
> Let d be the minimum required distance.
>
> First determine whether there is a solution. If not, report this
> and exit unsuccessfully.
>
> Else:
> Place the points (P_1 .. P_n) on G in a valid way (for instance
> by evenly distributing them).
>
> repeat
> Pick j randomly 1 <= j <= n.
> Remove P_j from G.
> Let S be the set of points of G such that the distance of
> each point of S to P_k (1 <= k <= n && k != j) is at least d.
> (Note that S cannot be empty, the previous position of P_j
> must be an element of S).
> Randomly select an element s of S, and place P_j on s.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This can be as hard as the original problem! In order to carry
out this step, you must have a reasonably complete description of the
space of all solutions - granted that's somewhat implied by the original
question, but implementation can be quite difficult. Here's a chart for
the maximum dimension of the solution space in the case of N 1x1 boxes
in a 3x3 grid:
N | max dimension
---------------------
1 | 2
2 | 4
3 | 6
4 | 8
5 | 7
6 | 6
7 | 4
8 | 1
9 | 0
<comment>
No Perl below - just more abstraction. Unless you like that
that kind of thing, it may not be an enjoyable read. IMHO
it's not necessarily off-topic for this thread.
</comment>
> until an_appropriate_time
>
> Invariant:
> A h, i: 1 <= h < i <= n: dist (P_h, P_i) >= d /\ P_h on G /\ P_i on G.
>
> The hard part is deciding when to stop, that is, when is the set
> random enough?
Providing a meaningful measure of randomness on the solution
space whose conditional probabilities are easily calculated is
no less problematic (e.g. 5 1x1 boxes in 9x9 grid), and in fact
intimately related to this problem.
IOW, you must determine a
_stopping time_ (see google(Random process stopping time) )
for your algorithm that makes the resulting process ( similar to
a random walk ) "uniformly distributed" over the solution space.
That too is a *very* *hard* problem, as your stopping time will be
path-dependent.
For example, consider the case of placing 3 1x1 boxes in a 2x2 box.
The solution space is ( the perimeter of ) a square. Naively
applying the above algorithm here is tantamount to constructing a
Markov process on the square along with a stopping time such that
1) successive points of the process always lie on the same
side of the square
2) the distribution of the "stopped" process is uniform
Constructing a process to carry out the algorithm as prescribed is
easy- for concreteness say the starting point is at A:
A ------ B
| |
Solution space = | |
| |
C ------ D
Now choose an adjacent side with equal probability, and distribute
the next point uniformly along that side. Repeat whenever you hit
another vertex; otherwise choose another point uniformly along the
same side. Call this process { X_n : n = 0 .. infinity }.
However, part (2) changes the nature of the process used for (1)
dramatically. What you want to do is choose a stopping time t
for the process {X_n} so that the function X_t is uniformly
distributed. Recalling that X_0 = A, the optimal choice is to set
t = 1 + s, where s = min { n : X_n = C or X_n = B } .
Hence, the quickest solution is to start at A, *wait* until
either B or C is hit, and *then* choose a point uniformly
along an adjacent side. Given the way {X_n} is constructed,
that could take a Very Long Time (TM).
In summary, what this algorithm appears to do is apply a general
scheme (constructing a Markov chain on a potentially degenerate
space) to attempt to solve a wide range of *very* *hard* problems-
in fact, the general case is too hard and too general.
AFAICT the practical range of applicability for this algorithm
isn't substantially greater than Craig's. And yes, Craig's is
a hell of a lot easier to implement than this one.
<aside>
That's not to say Craig's solution can't be improved.
In fact, I'm pretty sure the quadratic behavior can be
reduced substantially for cases where you need *lots*
of very small boxes. I just don't know of an elegant
way to do that.
</aside>
HTH
--
Joe Schaefer
------------------------------
Date: Sat, 20 Jan 2001 20:56:53 GMT
From: Jeffery Cann <jccann@catholic.org>
Subject: redirect and cookie (+domain) does not work!
Message-Id: <94cu2i$3p4$1@nnrp1.deja.com>
Greetings.
I have read several posts on redirects and set cookies in clpm.
However, the example below does not work.
I am trying to set a cookie for the server where the user is to be
redirected. So in example below, I go to http://localhost/cgi-
bin/try.cgi (my local apache server). The user will receive a redirect
message (to www.yahoo.com) and a cookie with domain (yahoo.com). When
the cookie includes the domain parameter, the cookie is not set.
I can send the same cookie without a domain and it will be set (but
this cookie will be for my 127.0.0.1 domain, not .yahoo.com).
Unfortunately, I want the domain to be the redirected server
(yahoo.com), not the one where this CGI runs (localhost). (NOTE:
domain names are only for example).
I have tested with NS 4.73 and IE 5.0 using Apache 1.3.14 (NT) and
Netscape Enterprize Server 3.6 on Solaris).
I suspect that the browsers are ignoring my set-cookie because it is
part of a redirect. Unfortunately, the Netscape Cookies spec
(http://www.netscape.com/newsref/std/cookie_spec.html) does not
explicitly state whether cookies are ignored during redirect.
Can anyone produce reference that confirms my suspicion? If not, what
gives with my example? It is too simple not to work...
Suggestions are greatly appreciated.
Thanks
Jeff
--------- try.cgi ----------------
#!d:/Perl/bin/perl
use CGI qw(:cgi);
my $url = 'http://www.yahoo.com';
use CGI qw(:cgi);
# without domain sets cookie
my $cookie=cookie(-name=>'without-domain', -value=>'is set', -expires
=> '+10d' );
# with domain does not set cookie
my $cookie=cookie(-name=>'with-domain', -value=>'is not set', -expires
=> '+10d', -domain => '.yahoo.com');
print redirect(-uri => $url, -cookie => $cookie );
------------- end ------------------------------
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sat, 20 Jan 2001 21:36:06 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Suppressing stderr on `` commands
Message-Id: <axna6.338$tg4.11475@eagle.america.net>
On 20 Jan 2001 18:25:02 GMT, Ben Okopnik <ben-fuzzybear@geocities.com> wrote:
>
>In my (admittedly short) experience with the default install of Solaris 8,
>'/usr/perl5/bin' is not part of $PATH, nor is '/usr/perl5/man' part of
>$MANPATH.
My default install of Solaris 8 doesn't have a /usr/perl5 directory.
It did have a perl executable in /bin, though. Of course, I compiled
perl from the distribution immediately after the Solaris installation
(and C compiler installation) and then modified my PATH and MANPATH
variables appropriately. No problem with perldoc; no problem
displaying Perl man pages.
--
Garry Williams
------------------------------
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 V10 Issue 107
**************************************