[13304] in Perl-Users-Digest
Perl-Users Digest, Issue: 714 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 3 22:07:38 1999
Date: Fri, 3 Sep 1999 19:05:09 -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 Fri, 3 Sep 1999 Volume: 9 Number: 714
Today's topics:
"Use <module>" Decide at run-time? <robert.l.flaugherREMOVE@trw.com>
Re: CGI in PERL pjgratz@my-deja.com
CGI.pm on linux <paulreid@cableinet.co.uk>
Re: CGI.pm on linux <paulreid@cableinet.co.uk>
Re: Getting table structure <makkulka@cisco.com>
Re: How to read webpages and post HTML forms with PERL <makkulka@cisco.com>
Image Upload!Help!!!! lchhooong@my-deja.com
Image Upload!Help!!!! lchhooong@my-deja.com
Re: Looking for tools. <agray@infoscience.otago.ac.nz>
multitasking in win32 (aka fork())? <baal@c2i.net>
Re: Newbie Question... <dheera@usa.net>
Padding a string with spaces? (Burt lewis)
Re: Perl / C Memory <dan@tuatha.sidhe.org>
Re: Perl and Threads <dan@tuatha.sidhe.org>
Re: perl or python w/MTS? <MHammond@skippinet.com.au>
perl script in linux crontab <mack@ncifcrf.gov>
Perl's underlying implementation of Arrays - Low Priori <nickread@primus.com.au>
Re: Perl's underlying implementation of Arrays - Low Pr <dan@tuatha.sidhe.org>
Re: printing (Burt lewis)
Re: Safe way to terminate blocking sub-threads? <dan@tuatha.sidhe.org>
Re: SEARCH and REPLACE <dheera@usa.net>
Re: Send to ICQ with perl (Hmmm....)
Re: Simulating Carriage Returns (Alan Curry)
Re: Simulating Carriage Returns (Alan Barclay)
Re: Simulating Carriage Returns (Larry Rosler)
To Mr. Christiansen, et al. <jdoerr@acsu.buffalo.edu>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 03 Sep 1999 17:05:47 -0700
From: Robert F <robert.l.flaugherREMOVE@trw.com>
Subject: "Use <module>" Decide at run-time?
Message-Id: <37D0625A.5088BADF@trw.com>
I am trying to create a general-purpose error-handling routine. One
feature would be that it would use caller-specific error information
that is saved in a module. However, the error handler won't know what
module to use to access this information until run-time. Is there a way
to do this? Here's the problem:
## Parameters.pm ###
package Parameters;
use Exporter();
@ISA = qw( Exporter );
@EXPORT = qw ( $errorMessage );
$errorMessage = "some error message";
## Driver.pl ###
use Parameters; # Parameters specific to this
program
use ErrorHandler;
handleError( "Parameters" ); # Handle some error using this data from
Parameters module
## ErrorHandler.pm ###
package ErrorHandler;
use Exporter();
@ISA = qw( Exporter );
@EXPORT = qw ( handleError );
sub handleError() {
use $_[0]; # <= I want to do this but can't
because it's not known until run-time
print "errorMessage\n"; # Is there some other way to do this???
}
Thank you.
------------------------------
Date: Sat, 04 Sep 1999 01:14:28 GMT
From: pjgratz@my-deja.com
Subject: Re: CGI in PERL
Message-Id: <7qprpd$bli$1@nnrp1.deja.com>
> And it's spelled Perl, not PERL.
'Technically' Nate is correct PERL is an acronym
for Practical Extraction and Reporting Language.
If Nate had been referring to the CGI.pm module
for PERL than he would have only needed to know
PERL, again technically speaking.
Of course knowledge of CGI would help prior to
creating PERL code using the CGI.pm module.
Just make sure you know what your talking about
before you slam someone. (Hope I dont eat my
words! eheh)
Besides were a community to help.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Sat, 04 Sep 1999 02:09:40 +0100
From: Paul Reid <paulreid@cableinet.co.uk>
Subject: CGI.pm on linux
Message-Id: <37D07154.E0EAF2AB@cableinet.co.uk>
--------------3EE65DF6071FA73E29D4779F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
hello,
I am trying out the CGI.pm module which is new to me.
I have successfully tried it on a unix server and on my PWS but when i
try to run it on a Linux server I get an error.
On contacting my server people they told me it may be because it
contains dos line feeds and this is the error log:
Can't find string terminator "END_OF_AUTOLOAD" anywhere before EOF at
CGI.pm line 694.
BEGIN failed--compilation aborted at
/home/ftp/htdocs/paulreid/cgi-bin/cgitest.cgi line 3.
[Wed Sep 1 10:47:18 1999] [error] [client 194.117.142.83] Premature end
of script headers: /home/ftp/htdocs/paulreid/cgi-bin/cgitest.cgi
I have looked through the CGI.pm file and counted the lines to line694
and cant see anytrhing to do with dos there and to be honest I dont
really know what it is I am looking for.
Can anyone help me here?
Paul
--------------3EE65DF6071FA73E29D4779F
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<HTML>
hello,
<BR>I am trying out the CGI.pm module which is new to me.
<BR>I have successfully tried it on a unix server and on my PWS but when
i try to run it on a Linux server I get an error.
<BR>On contacting my server people they told me it may be because it contains
dos line feeds and this is the error log:
<P>Can't find string terminator "END_OF_AUTOLOAD" anywhere before EOF at
<BR>CGI.pm line 694.
<BR>BEGIN failed--compilation aborted at
<BR>/home/ftp/htdocs/paulreid/cgi-bin/cgitest.cgi line 3.
<BR>[Wed Sep 1 10:47:18 1999] [error] [client 194.117.142.83] Premature
end
<BR>of script headers: /home/ftp/htdocs/paulreid/cgi-bin/cgitest.cgi
<P>I have looked through the CGI.pm file and counted the lines to line694
and cant see anytrhing to do with dos there and to be honest I dont really
know what it is I am looking for.
<BR>Can anyone help me here?
<BR><I><U>Paul</U></I></HTML>
--------------3EE65DF6071FA73E29D4779F--
------------------------------
Date: Sat, 04 Sep 1999 02:13:31 +0100
From: Paul Reid <paulreid@cableinet.co.uk>
Subject: Re: CGI.pm on linux
Message-Id: <37D0723B.BE9FF8E1@cableinet.co.uk>
> here is the Calling script:
#!/usr/bin/perl -w
use CGI;
$co = new CGI;
print $co-> header,
$co->start_html (-title=>'CGI Example'),
$co->center($co->h1('Welcome to CGI')),
$co->textarea(
-name=>'textarea',
-default=>'No opinion',
-rows=>10,
-columns=>60
),
$co->end_html;
------------------------------
Date: Fri, 03 Sep 1999 16:20:37 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Getting table structure
Message-Id: <37D057C5.F607A5CC@cisco.com>
[ Paulius wrote:
> is it possible to get a table structure using DBI/DBD/ODBC like in
> JDBC with DatabaseMetaData? [getColumns()]
> if yes, then how?
--
Yes.
After a $sth->execute() call is done
$sth->{NAME} will point to an array ref containing the names of the
cols.
For eg to get first col name
print "First column name: $sth->{NAME}->[0]\n";
Whether this works or not depends on whether the DBB for your DB
supports this or no.
You have to experiment. For more information read the DBI API doc.
--
------------------------------
Date: Fri, 03 Sep 1999 17:15:55 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: How to read webpages and post HTML forms with PERL
Message-Id: <37D064BA.9C603ACC@cisco.com>
["Leonid A. Elbert" wrote:
> Can anybody give me an advice how to make a script that
> 1) connects to a webserver and read through the contents of a html page
> 2) posts a HTML form to a webserver
> (All this without using a browser, of course.)
perldoc LWP::Simple
perldoc LWP::UserAgent
perldoc HTTP:Request
perldoc HTTP::Response
perldoc HTTP::Message
You are lucky. You will find the code you need in these docs !!
--
------------------------------
Date: Fri, 03 Sep 1999 23:37:18 GMT
From: lchhooong@my-deja.com
Subject: Image Upload!Help!!!!
Message-Id: <7qpm3d$7p5$1@nnrp1.deja.com>
Hi ,
I am buliding my own homepage, and I want to have a photo upload
function ! But I just want to upload or allow my friends to upload gif
or jpg photo, I don't want them to take all the space in my disk, so, I
just wondering do you know how to do it?
I am using perl to create it, if you know how to do it in perl or java,
can you let me know? thank you!
Actually I tried to hard code the $filename, so when my friends
uploaded their photo , they need to type the photo name xxx.jpg or
xxx.gif in the text box, but I just don't want to hard coded this part.
DO you have any better way to make the program understand the file they
pick up is jpg and gif? So that my friends can just type in whatever
they like. HOpe to hear your reply as soon as possible!
Thank you!
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 03 Sep 1999 23:37:16 GMT
From: lchhooong@my-deja.com
Subject: Image Upload!Help!!!!
Message-Id: <7qpm3b$7p3$1@nnrp1.deja.com>
Hi ,
I am buliding my own homepage, and I want to have a photo upload
function ! But I just want to upload or allow my friends to upload gif
or jpg photo, I don't want them to take all the space in my disk, so, I
just wondering do you know how to do it?
I am using perl to create it, if you know how to do it in perl or java,
can you let me know? thank you!
Actually I tried to hard code the $filename, so when my friends
uploaded their photo , they need to type the photo name xxx.jpg or
xxx.gif in the text box, but I just don't want to hard coded this part.
DO you have any better way to make the program understand the file they
pick up is jpg and gif? So that my friends can just type in whatever
they like. HOpe to hear your reply as soon as possible!
Thank you!
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 04 Sep 1999 13:44:34 +1200
From: Andrew Gray <agray@infoscience.otago.ac.nz>
Subject: Re: Looking for tools.
Message-Id: <u4shbfo1p.fsf@infoscience.otago.ac.nz>
"Sidney Orret" <orret@wmn.net> writes:
> What are the best enviroment and tools for PERL's
> programming??????????????
One question mark would do just fine thanks. BTW, it's Perl for the
language and perl for the implementation by convention. You may,
perhaps, disregard that convention, but it is never PERL (not ever).
You seem to be looking for an editor and I would almost always
recommend Emacs over any other (except perhaps vi). Since you appear
to be using an MS Win machine see
http://www.cs.washington.edu/homes/voelker/ntemacs.html
for instructions about downloading the binary, installing, etc. for
NT Emacs and
http://www.vim.org/
for the same about VIM (Windows binaries are available).
> Currently I am using Viotix PERLPad 3.5, and the Programmer's File
> Editor 1.01, but I am looking for something with more facilities as
> sintax highligt for example. Also I am looking for a shareware, and
> better for a freeware.
Both Emacs and vi are free.
Emacs will do anything you can think of asking it to do. Syntax
highlighing is available for many programming languages, including
Perl. By default any file with the extension .pl should be
automatically highlighted. As with anything in Emacs, you can change
and further customise to your heart's content. You can run your
scripts from within Emacs and have the output appear in another
buffer---which may be helpful when you're experimenting/learning.
Emacs is also aware of the perl debugger.
Or you may prefer vi of course.
There is a considerable learning curve with Emacs, but you can do most
of what you want with the menus and learn keystrokes a few at a time.
I'd suggest getting a copy of the Emacs reference card (search for
"Emacs Reference Card" and you should find plenty) and keeping that
handy.
You may wish to limit your posts to one group next time. People are
friendlier that way. Of course Perl people are pretty friendly to
start with and you may not want them to become any friendlier.
Cheers,
Andrew
------------------------------
Date: Sat, 04 Sep 1999 00:41:54 GMT
From: "[L] Vicious!" <baal@c2i.net>
Subject: multitasking in win32 (aka fork())?
Message-Id: <mVZz3.1126$6g7.125490@juliett.dax.net>
I have built a perl program using Tk (Win GUI), and my program has some
long-running sub-functions. I run Win98 & Activestate perl, is there any way
to obtain some kind of multitasking (aka fork()). This will allow me to make
some progress indicators, and still update the mainloop (avoid a "dead"
interface). I've tried the Win32::Process, but I couldn't find a way to
execute my functions. I might be wrong, but the Win32::Process is used to
run external aplications and not functions inside my program.
I couldn't find it in the docs, but if there are a section refering to my
problem, don't hesitate to tell me. :O)
------------------------------
Date: Fri, 03 Sep 1999 23:39:36 GMT
From: Dheera <dheera@usa.net>
Subject: Re: Newbie Question...
Message-Id: <7qpm7m$7q0$1@nnrp1.deja.com>
You want to actually include the contents into the perl script as if it
were a piece of code? First, the file you include must be in the same
directory as the perl script, and have an extension .pm (txt files not
allowed)....
So if you've named it doc1.pm, just type
use doc1;
in your perl script...
Hope this helps,
Dheera
In article <3URz3.506$uq.11352@news2.voicenet.com>,
"clavikal" <clavikal@voicenet.com> wrote:
> I am completely new to Perl, so please pardon any questions that may
seem
> stupid, as you will probably be hearing a lot of them ;o).
>
> How can I simply include a .txt file into a perl script ( dynamic-gen
web
> page ).? i.e. want to include "doc1.txt" residing
in /htdocs/docs/doc1.txt
>
> ( I'm using Apache )
>
> Thanks,
> clavikal
>
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Sat, 04 Sep 1999 01:25:54 GMT
From: burt@ici.net (Burt lewis)
Subject: Padding a string with spaces?
Message-Id: <Cy_z3.7$9b.942@news.goodnet.com>
Hi,
I have a text database that I need to make certain fields left justified so I'm
assuming I need to pad them with spcaces.
my database looks something like:
apples:steak:12345 :juice:
My goal is to get this to look like:
apples:steak: 12345:juice:
Appreciate any help with this.
Burt Lewis
------------------------------
Date: Sat, 04 Sep 1999 01:05:28 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Perl / C Memory
Message-Id: <sf_z3.148$lT.809@news.rdc1.ct.home.com>
samuel Lellouche <sam@khan.epita.fr> wrote:
> Here is what i noticed;
> (I'm on NetBSD 1.4 with perl, version 5.004_04 built for i386-netbsd)
> here is test.c :
[Standard perlman.c analog snipped]
> as explained in the mans.
> Here is the client_init2.pl:
> print "Perl Execution\n";
> i'm doing a top during the execution:
> MEM
> 11639 netsoul 10 0 680K 928K sleep 0:00 0.00% 0.00% test
> a few secs after
> 11639 netsoul 10 0 1788K 2036K sleep 0:00 0.00% 0.00% test
> still a few secs later
> 11639 netsoul 10 0 2224K 2472K sleep 0:00 0.00% 0.00% test
> the .pl file is very light.. this memory problem is much bigger when the
> .pl includes some "require" and more code....
Well, require does yank in more perl code, which can potentially eat a lot
of memory. (If you, say, required something that used CGI, IO, and POSIX
you could expect to chew a good chunk of memory)
> It seems to me that the perl interpreter dosn't free everything it uses...
Sure it does. Unfortunately just because perl frees memory doesn't mean
memory is returned back to the system. With very few exceptions (I think
MacOS and, under a few circumstances, VMS) any memory allocated to a
process by the OS stays with that process until it exits. This isn't a
perl thing--any program that mallocs memory will do it.
Don't sweat the memory usage that much--if it's truly unused your OS will
eventually swap it out and leave it swapped out.
Dan
------------------------------
Date: Sat, 04 Sep 1999 00:57:27 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Perl and Threads
Message-Id: <X7_z3.146$lT.809@news.rdc1.ct.home.com>
In comp.lang.perl.modules Steven Cruz <steve@nextopia.com> wrote:
> I am have a problem when I use the threads with perl. I will get a
> zombie thread once every 500 times or so. :( I was wonder what I should
> be doing to fix this problem. Any suggests?
What OS are you using? (I'm presuming Linux, but it's not at all clear)
And do you have any signal handlers in your program? (SIGCHLD may mess up
the way Linux does threads, I'm not 100% sure) And are you joining or
detaching all your threads? (dead but unjoined threads could conceivably
show as zombies the way linux does things)
You also should go snag the latest thread libraries and patches for your
OS, whatever it is. That may help too. (As would more details, like the
output from perl -V...)
Dan
------------------------------
Date: Sat, 4 Sep 1999 10:07:44 +1000
From: "Mark Hammond" <MHammond@skippinet.com.au>
Subject: Re: perl or python w/MTS?
Message-Id: <7qpnte$64i$1@m2.c2.telstra-mm.net.au>
Python and MTS work fine(*). There is not much to say about it, as it "just
works". Python fully supports all the COM threading models, and this is
also true under MTS - however, as MTS runs objects in its own process, the
objects are all out-of-process, so most of the threading model
considerations dont apply.
* There is a bug in win32all-125 that can crash the MTS package. This
happens when multiple MTS threads all attempt to start using Python at the
same time. This bug has been fixed so is available from the CVS source
archive or in the soon to be release win32all-126.
Mark.
nielsenjf@my-deja.com <nielsenjf@my-deja.com> wrote in message
<7qorpv$jpq$1@nnrp1.deja.com>...
> In cases where I don't want to write C++ and would rather not use VB to
> createa component that lives in MTS, perl or python would be a great
> alternative if they work out well.
>
> It looks like each can create COM components, but I don't see a lot of
> stuff regarding their use with MTS.
>
> How well do each function with it? For example, what type of apartments
> can they live in? It is all only IDispatch based?
>
> Any good examples of typical components written in perl or python for
> MTS?
------------------------------
Date: Sat, 04 Sep 1999 00:15:58 +0000
From: mack <mack@ncifcrf.gov>
Subject: perl script in linux crontab
Message-Id: <37D064BE.87981DAB@ncifcrf.gov>
I have a perl script which runs fine under
linux and solaris and as a crontab entry in
solaris, but which doesn't run as a crontab
under linux (nothing happens as far as I
can see). The script takes command arguments
#./foo.pl foo
The linux crontab manpage says that a crontab
command is run as the argument to sh -c giving
#sh -c ./foo.pl foo
Here the script acts as if it was invoked without
the argument "foo"
How do I get crontab perl scripts to run under linux?
Thank you
Joe
--
Joseph Mack, NA3T, FM05lw EME(B,D)
AZ_PROJ map server at http://www.wm7d.net/azproj.shtml
mailto:mack@ncifcrf.gov
------------------------------
Date: Sat, 4 Sep 1999 11:23:57 +1000
From: "Nick Read" <nickread@primus.com.au>
Subject: Perl's underlying implementation of Arrays - Low Priority
Message-Id: <936408311.376813@diddley.primus.com.au>
Hey all,
This is to all those people out there who have fiddled with Perl's innards
and know how it's data structures are implemented.
Now I assume that since Perl's arrays are dynamic (grow/shrink) they are
probably implemented as some form of linked-list in the underlying C code.
If this is the case, then shifting or unshifting an item from the beginning
of an array should be very efficient (simply changing a couple of
references).
But what if the implementation of the linked-list is one of the types where
more than one elements are kept in each list node? (as opposed to one
element per node). This would mean that shifting (or unshifting) a value
from the beginning would cause a complete reshuffle of the list.
Now I personally haven't had the time to study Perl's source code and see
how these are done; that's why I'm asking anyone who knows. Why do I want
to know this? Well, if the second case is true (multiple elements per node)
then in certain circumstances it may be more efficient to actually implement
a linked list in Perl if you need much shifting/unshifting, as opposed to
using the built-in array type.
You may be thinking that I should just pop/push from the end of an array
instead which would stop the array from requiring a reshuffle, and this is
true. But if Perl's arrays are implemented as in case 1 (single element per
node) than this would be just as inefficient because a complete traversal of
the list is required to reach the end, while case 2 would be slightly more
efficient.
So how are Perl's arrays implemented?
Please note that this whole question is based on the fact that I assume it's
a type of linked list implementation. For all I know, it's something
completely different.
Best Regards,
Nick Read
==========================
"Calculus is the mathematics of change and differential
equations are the engines of calculus."
-- J. M. A. Danby
==========================
P.S. This is all just a passing intrest of mine to know and not a priority
in any way!
------------------------------
Date: Sat, 04 Sep 1999 01:34:05 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Perl's underlying implementation of Arrays - Low Priority
Message-Id: <hG_z3.154$lT.757@news.rdc1.ct.home.com>
Nick Read <nickread@primus.com.au> wrote:
> So how are Perl's arrays implemented?
Perl's arrays are really arrays. Perl allocates a chunk of memory to hold
SV * (the underlying perl "thing"), and keeps a pointer to the beginning
of the array as perl sees it, the real beginning of the array, and the end
of the array as perl sees it (amongst other things)
When you shift things off the front of the array, perl just moves the
'beginning of array' pointer over by one. When you pop something off the
end it just moves the end of the array pointer. When you unshift something
on, perl will move the beginning pointer if there's empty space at the
beginning or really shift everything over if there's not. When you push on
the end, perl will just move the end of array pointer if there's unused
space (which there often is, as perl allocates some padding for just such
an occasion) or reallocs the array if there isn't. Inserting into the
middle causes perl to do a block move of everything past the insert point.
So basically if you unshift on the beginning or push on the end you can
potentially end up shifting memory, and if you splice in the middle you
definitely will. With either one you may trigger a realloc.
If you think this is inefficient, it actually isn't. It works very well
for the common usage of arrays, which is the way you want it. (The common
things should be fast. Uncommon or messy things can be slower)
Dan
------------------------------
Date: Sat, 04 Sep 1999 01:30:42 GMT
From: burt@ici.net (Burt lewis)
Subject: Re: printing
Message-Id: <6D_z3.9$9b.942@news.goodnet.com>
I looked into this also and hit a dead end. I even tried to embed page break
escape characters without luck. Printing efficiency seems to be lacking yet in
HTML.
Burt Lewis
In article <7qoek2$9js$1@nnrp1.deja.com>, dgold1@my-deja.com says...
>
>Is there a way to include printer control characters in an HTML doc. I
>need to force page breaks, adjust headers and footers while printing
>some pages. I am using a PERL cgi-script to generate the HTML. I have
>tried counting lines, characters, etc... but depending on what is being
>printing the counts are off.
>
>Any ideas?
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.
------------------------------
Date: Sat, 04 Sep 1999 01:20:30 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Safe way to terminate blocking sub-threads?
Message-Id: <yt_z3.151$lT.757@news.rdc1.ct.home.com>
Martin H. Sluka <martin@sluka.de> wrote:
> I'm currently working on the data collector script for a monitoring
> system. The basic idea is to have a script running as a daemon, that
> each 30 seconds spawns a number of worker threads--say about a dozen--,
> which themselves each call one external helper script or program that
> does some data collecting--e.g., but not only, via SNMP--, handle the
> results back to the main thread, which then validates the data and
> delivers it to a central SQL database.
Sounds good.
> I'd like to implement the whole task mainly using Perl's new threading
> capabilites. The problem however is, that the external scripts that are
> started by the worker threads are supposed to be potentially dumb and
> therefore maybe blocking, so the child threads would also block.
You might try firing them off with magic open (i.e. open(FH, "foo |")) and
use select to check if there's data on the filehandle. Select does take a
timeout. (Note that I haven't actually tried this)
> Therefore I had planned to have them do their work in an eval() block
> and set a timeout using alarm() and a $SIG{ALRM} = sub die {"TIMEOUT\n"}
> handler.
Ack! Bad Idea.
> However, after experimenting a bit with threads and such a handler, I
> found out, that whereever I set the timeout, it always and only seems
> to affect the main thread, so the worker threads would still block.
> Needless to say, this is not what I wanted.
As you've found. Here's a good rule of thumb to remember:
Threads and Signals Do Not Mix. Ever. Anywhere.
POSIX threads have this problem no matter what language or platform. The
basic problem is that signals are a process-level thing rather than a
thread-level thing. The OS really has no idea which thread should get a
signal.
> I then again took a look at perlthrtut(1) and the various Thread::*
> manpages to find a way to safely interrupt and stop a blocking sub
> thread, but found none.
There isn't one.
> Now, as a workaround I came up with the following concept (which I have
> _not_ implemented yet):
> The data collector daemon (DCD) would fork() a new sub process (SP)
> each 30 seconds. This sub process then creates the threads which start
> the external helper scripts. Each of these threads gets a Thread::Queue
> to communicate with the SP.
Won't work. Thread structures don't work across processes, which is what
you'd get with the fork.
> The SP then waits some time to give its worker threads a chance to
> collect the data, then examines the queues to see which of them
> successfully completed their work, validates the data, writes it into
> the database and then simple kills itself with all its possibly still
> blocking sub threads.
Yuck. Too convoluted. If you really want, record the pids of the
created subprocesses (if you can find it--you might have to do nasty
things with parsing ps output) and have a monitor thread sleep() for, say,
10 seconds (or however long) and kill the created subprocesses.
> The longer I think about that, the uglier it seems to me. :-) :-/
> So the questions remains: Is there any nicer way to solve this problem?
> Is using threads perhaps the wrong way at all?
Possibly, but I don't think so. The problem is there's no good way to
unblock a blocked thread. That may change with 5.6, but I don't know if
it'll help you here. (The first person to suggest async cancellation
*will* get a smack...)
Also, in addition to the magic open way (which is a bit less prone to
blocking than system() or backticks), you could do a straight fork/exec,
then set an alarm, then do the execution. Forking a threaded process
leaves only the thread doing the forking running. (No this isn't
documented anywhere. perlthread.pod's only half done at the moment)
> Would it perhaps be better instead to have the SPs run as distinct pro-
> cess so that I can individually set a timeout in each of them, and have
> them pass the results of the helper scripts they call to the DCD using
> sockets?
Possibly. I'd still give the select a try.
> Or to just do it the old-fashioned way, that is, forget about that
> whole threading thing, leave it at calculating prime numbers, :-) and
> open()ing the helper scripts right from the main program with pipes--
> which of course also do an implicit fork()--and use a select()-loop,
> killing the child processes if they didn't terminate within the given
> period?
I'd still go with threads, and have each thread manage a single
subprocess. (A lot more straightforward than selecting on lots of
filehandles)
> Sorry, I just came up with that idea while writing this article. Sounds
> reasonable to me, "pretty straightforward", as perlthrtut(1) would cer-
> tainly say. ;-) Are there any severe pitfalls to it?
Of course. It might work, and *then* where would you be? :-)
Dan
------------------------------
Date: Fri, 03 Sep 1999 23:42:18 GMT
From: Dheera <dheera@usa.net>
Subject: Re: SEARCH and REPLACE
Message-Id: <7qpmco$7s5$1@nnrp1.deja.com>
Hmm... would this work? (Hope you've got your screen wide enough so it
doesn't wrap the lines over)
$c=qq|sys "a-b" "c*a" "(xyz+b)"\ntest "xyxx*2" "abc+2" "fcy*2"|;
$c=~s/([a-z0-9])+\s+\"([^\"]*?)\"\s+\"([^\"]*?)\"\s+\"([^\"]*?)\".*/
\$$1=\'$2\'; \'$3\'; \'$4\';/img;
print $c;
________________________________________
In article <7qkkrf$iqt$1@nnrp1.deja.com>,
tvn007@my-deja.com wrote:
> Hi,
>
> Would someone help me with this:
> I would like to change the following line from:
>
> sys "a-b" "c*a" "(xyz+b)"
> test "xyxx*2" "abc+2" "fcy*2"
>
> to
>
> $sys = '$a-$b'; '$c*$a'; '($xyz+$b)';
> $test = '$xyxx*2'; '$abc+2' ;'$fcy*2';
>
> Thanks for your help,
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 03 Sep 99 23:24:51 GMT
From: mail-abuse@uu.net (Hmmm....)
Subject: Re: Send to ICQ with perl
Message-Id: <7qplhv$kfl$1@bgtnsc03.worldnet.att.net>
Yeah, you were rude. Your answer was in the form of an "all knowing" kludge
writer who couldn't be bothered with the question and wanted to belittle the
posting individual. Shame. You could have opened up a meaningful dialog and
helped someone learn more about Perl and explored a way of working a solution.
Instead you just fosterd frustration and put a bad light on asking for help.
In short, you were an asshole.
> tony@showroom.org.uk (Tony Kennick) writes:
>>
>> If you are going to be rude, be right.
>
>1) I was not rude. I pointed the person to a possible place to find
> what they needed, and even told them how to get there.
>
>2) I was right. The information was accurate and to the point.
>
>What is your problem anyway? If you consider my post rude, then you
>seriously have a big problem.
>
>I don't think I need to see more of your posts.
>
>Martien
------------------------------
Date: Fri, 03 Sep 1999 23:08:19 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: Simulating Carriage Returns
Message-Id: <DxYz3.840$r5.54918@typ11.nn.bcandid.com>
In article <7qpjl3$49q$1@charm.magnus.acs.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Larry Rosler
><lr@hpl.hp.com>],
>who wrote in article <MPG.123996bef7a1c480989f15@nntp.hpl.hp.com>:
>>
>> About time_t, the Standard says simply that it must be an arithmetic
>> type 'capable of representing times'.
>
>Thanks for confirming my opinion and refuting one of Alan Curry.
He didn't refute me, and I don't think he intended to. time_t does not have
to be 32 bits. It just can't be a long long as you suggested because long
long is not one of the "arithmetic types" defined by the standard. If you
wanted it to be bigger than long, you'd have to make it a floating point
type. Which, while conforming, would probably not be appreciated by users.
C9X blows all the rules to hell though.
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: Sat, 04 Sep 1999 00:09:58 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: Simulating Carriage Returns
Message-Id: <936404050.625663@elaine.drink.com>
In article <DxYz3.840$r5.54918@typ11.nn.bcandid.com>,
Alan Curry <pacman@defiant.cqc.com> wrote:
>
>He didn't refute me, and I don't think he intended to. time_t does not have
>to be 32 bits. It just can't be a long long as you suggested because long
>long is not one of the "arithmetic types" defined by the standard. If you
>wanted it to be bigger than long, you'd have to make it a floating point
>type. Which, while conforming, would probably not be appreciated by users.
On all current implementations that I'm aware of., time_t is a typedef,
usually to int. Is there any requirement for this? If not, then it would
seem to be valid to make time_t a 64 bit value even if char->long aren't.
------------------------------
Date: Fri, 3 Sep 1999 18:07:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Simulating Carriage Returns
Message-Id: <MPG.123a1091f3311a52989f17@nntp.hpl.hp.com>
In article <936404050.625663@elaine.drink.com> on Sat, 04 Sep 1999
00:09:58 GMT, Alan Barclay <gorilla@elaine.drink.com> says...
> In article <DxYz3.840$r5.54918@typ11.nn.bcandid.com>,
> Alan Curry <pacman@defiant.cqc.com> wrote:
> >
> >He didn't refute me, and I don't think he intended to. time_t does not have
> >to be 32 bits. It just can't be a long long as you suggested because long
> >long is not one of the "arithmetic types" defined by the standard. If you
> >wanted it to be bigger than long, you'd have to make it a floating point
> >type. Which, while conforming, would probably not be appreciated by users.
>
> On all current implementations that I'm aware of., time_t is a typedef,
> usually to int. Is there any requirement for this? If not, then it would
> seem to be valid to make time_t a 64 bit value even if char->long aren't.
The point was made jokingly about making it a double, but this works OK
even if there are no 64-bit integers. It provides about 52 bits of
precision and can be compared to (double)-1 to test for failure.
Maybe this is a reasonable way to go in general.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 03 Sep 1999 20:52:06 -0400
From: Jean C Doerr <jdoerr@acsu.buffalo.edu>
Subject: To Mr. Christiansen, et al.
Message-Id: <37D06D36.7574@mail.wzrd.com>
Hi.
I've a question of protocol. When I produce a document for my perl
scripts/program, what type of perl credits are expected of me, among
things like, Sun Solaris is a trademark of..., etc?
Thank you,
-jc
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu.
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 714
*************************************