[19680] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1875 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 5 03:10:31 2001

Date: Fri, 5 Oct 2001 00:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1002265813-v10-i1875@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 5 Oct 2001     Volume: 10 Number: 1875

Today's topics:
    Re: pervent multiple instances of a server (David Efflandt)
    Re: pervent multiple instances of a server <goldbb2@earthlink.net>
        programmers/partners wanted in NJ/NY/PA/CT <rtrahan@monmouth.com>
    Re: robot in perl <fragil@mcnet.ch>
    Re: robot in perl <ilya@martynov.org>
    Re: Skipping following lines if the same (Bernard El-Hagin)
    Re: Skipping following lines if the same <uri@sysarch.com>
    Re: Skipping following lines if the same (Bernard El-Hagin)
    Re: Template-Toolkit <ilya@martynov.org>
    Re: Trapping sendmail errors (with eval?) (Bill Dykstra)
        Uninstall under Windows ME (Mike Filippo)
    Re: Uninstall under Windows ME <rob_13@excite.com>
    Re: using secure cgi space? (David Efflandt)
        what am I doing wrong ? (Tana)
    Re: what am I doing wrong ? <jeff@vpservices.com>
    Re: Why does if statement not work ? benhopkins@mindspring.com
    Re: Yet another fork question <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 5 Oct 2001 02:29:48 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: pervent multiple instances of a server
Message-Id: <slrn9rq6os.dmg.efflandt@typhoon.xnet.com>

On Thu, 04 Oct 2001 13:52:18 +0200, Thomas Bätzler <Thomas@Baetzler.de> wrote:
> On 4 Oct 2001 04:02:26 -0700, perlmisk@yahoo.co.uk (perl misk) wrote:
>>what is the best way to prevent multiple instances of a server from
>>being invoked?
> 
>>3. try connecting to a predefined socket
> 
> You probably mean binding instead of connecting.

That should work if the server uses a specific socket that nothing else
uses.  I have a Perl fake smtp daemon that just listens to port 25 and
bounces back a "554 Service not available" message, and when I try to
start a second instance of it, it dies with:

bind: Address already in use at ./fakemail line 33.

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


------------------------------

Date: Fri, 05 Oct 2001 02:33:38 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: pervent multiple instances of a server
Message-Id: <3BBD5442.B2716BB0@earthlink.net>

perl misk wrote:
> 
> what is the best way to prevent multiple instances of a server from
> being invoked?
> 
> possible solutions I can think of are:
> 
> 1. $ps = `ps -fuusername`;
>    m/$ps/$server_name/
> 
> this seems a little messy, and a server could be started after you
> call ps but before you get to start yours
> 
> 2. sub start_server {
>        open >>FH, ~/tmp/server_running.lock
>    }
> 
> ditto
> 
> 3. try connecting to a predefined socket
> 
> ??

As Thomas Bätzler said, you mean try binding to a predefined socket.

Anyway...

4.  get an exclusive lock on some file [using flock].

        use Fcntl qw(:flock);
        die "The server is already running.\n"
                unless( flock(DATA, LOCK_EX|LOCK_NB) );

5. use a semaphore or shared memory operation to get exclusive access to
a resource.  Search in perlfunc for "System V interprocess communication
functions", and look at the docs for each.  I'm sure you could use those
somehow to do it, though I don't know precisely how.

6.  Count, using stat, the number of "links" to the program file.  It
should be 2: one directory entry, one open file [perl holding the script
open]:
	die "Program is already running\n"
		if (stat $0)[3] > 2;
or:
	die "Program is already running\n"
		if (stat DATA)[3] > 2;

7. There is no 7.

8. use the readpipe builtin. :) this is the same as 1.

9. kindly and politely ask the user to not do that, and ignore the
problem.

10. ignore the problem, and scream and complain loudly if evidence
indicating multiple instances are running is found.

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: Thu, 04 Oct 2001 21:26:22 -0700
From: Richard Trahan <rtrahan@monmouth.com>
Subject: programmers/partners wanted in NJ/NY/PA/CT
Message-Id: <3BBD366E.A8CA159F@monmouth.com>

I am a just-retired programmer in Monmouth County, NJ. I would like
to network with experienced programmers in NJ/NY/PA/CT for the purpose
of starting a porting business. You should be a guru in at least one
freeware and one payware language and/or IDE and/or O.S.
(e.g., {Perl,Java,Python,Forte,Linux} {C/C++,Delphi,Windows}). Mostly
telecommuting, depending on job. I am looking for working partners,
not wage slaves. Absolutely no investment or other hitches. Visit my
web pages at www.monmouth.com/~rtrahan and www.rockyboat.com.

RSVP private email.


------------------------------

Date: Fri, 05 Oct 2001 07:51:38 +0200
From: Gilles =?ISO-8859-1?Q?Fragni=E8re?= <fragil@mcnet.ch>
Subject: Re: robot in perl
Message-Id: <3BBD4A6A.5080509@mcnet.ch>

Try reading the O'Reilly Book : Perl Cookbook by Tom Christinasen & 
Nathan Torkington wich is an excellent reference about advanced Perl 
development.

Make a search on altavista with the criteria : "LWP::RobotUA(3)" or find 
informations on CPAN about it.

Good luck...

G. F.



------------------------------

Date: 05 Oct 2001 10:15:12 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: robot in perl
Message-Id: <87d742pq8f.fsf@abra.ru>

>>>>> On Fri, 05 Oct 2001 00:44:19 GMT, "Pujo C A" <adustipujo1@mediaone.net> said:

PCA> anybody knows any good references to make robot in perl?
PCA> thanks

Don't ignore google (www.google.com). You should just enter these
keywords: Robot Perl. Simple search and you don't need to wait for
answers in news group anymore.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


------------------------------

Date: Fri, 5 Oct 2001 05:37:07 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Skipping following lines if the same
Message-Id: <slrn9rqhbp.8li.bernard.el-hagin@gdndev25.lido-tech>

On Thu, 04 Oct 2001 20:23:58 GMT, Michael Budash <mbudash@sonic.net> wrote:
>In article <slrn9roght.8li.bernard.el-hagin@gdndev25.lido-tech>, 
>bernard.el-hagin@lido-tech.net (Bernard El-Hagin) wrote:
>
>> [snip]
>>
>> for ( my $i = 0; $i < @data; $i++ ){ 
> 
>very un-perlish... use this:


If it were "un-perlish" it wouldn't be in Perl. Duh.


Cheers,
Bernard


------------------------------

Date: Fri, 05 Oct 2001 05:42:33 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Skipping following lines if the same
Message-Id: <x7lmiq8wwn.fsf@home.sysarch.com>

>>>>> "BE" == Bernard El-Hagin <bernard.el-hagin@lido-tech.net> writes:

  BE> On Thu, 04 Oct 2001 20:23:58 GMT, Michael Budash <mbudash@sonic.net> wrote:
  >> In article <slrn9roght.8li.bernard.el-hagin@gdndev25.lido-tech>, 
  >> bernard.el-hagin@lido-tech.net (Bernard El-Hagin) wrote:
  >> 
  >>> [snip]
  >>> 
  >>> for ( my $i = 0; $i < @data; $i++ ){ 
  >> 
  >> very un-perlish... use this:

  BE> If it were "un-perlish" it wouldn't be in Perl. Duh.

wrong. you can code in c style in perl and it is still un-perlish. c for
loops are rarely needed or used in perl code. seeing usually raises a
flag that the rest of the code could be weak. the fact that perl
supports a feature doesn't mean it should be the primary way to do
something. c for loops have their place but perl foreach loops are
usually the better way in almost all cases.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


------------------------------

Date: Fri, 5 Oct 2001 05:53:25 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Skipping following lines if the same
Message-Id: <slrn9rqiaf.8li.bernard.el-hagin@gdndev25.lido-tech>

On Fri, 05 Oct 2001 05:42:33 GMT, Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "BE" == Bernard El-Hagin <bernard.el-hagin@lido-tech.net> writes:
>
>  BE> On Thu, 04 Oct 2001 20:23:58 GMT, Michael Budash <mbudash@sonic.net> wrote:
>  >> In article <slrn9roght.8li.bernard.el-hagin@gdndev25.lido-tech>, 
>  >> bernard.el-hagin@lido-tech.net (Bernard El-Hagin) wrote:
>  >> 
>  >>> [snip]
>  >>> 
>  >>> for ( my $i = 0; $i < @data; $i++ ){ 
>  >> 
>  >> very un-perlish... use this:
>
>  BE> If it were "un-perlish" it wouldn't be in Perl. Duh.
>
>wrong. you can code in c style in perl and it is still un-perlish.


Jeez, I know. I was being defensive. :)


[unnecessary explanation snipped]


The reason I used the C style loop is that the OP used one
and I wasn't sure whether he/she/it needed a C style loop for
other reasons or not. The question was how to make the loop
work and I answered that question.


Cheers,
Bernard


------------------------------

Date: 05 Oct 2001 10:08:53 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Template-Toolkit
Message-Id: <87hetepqiy.fsf@abra.ru>

>>>>> On Thu, 04 Oct 2001 14:29:09 GMT, Bart Lateur <bart.lateur@skynet.be> said:

BL> Actually, I have no clue whether you'll like it or not, but at least,
BL> there's an article written about it. Check it out.

BL> 	<http://www.perl.com/pub/a/2001/01/tt2.html>

Also it is worth to read this article:

    http://perl.apache.org/features/tmpl-cmp.html

It covers several different templating systems.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


------------------------------

Date: 4 Oct 2001 18:27:36 -0700
From: bill@ilap.com (Bill Dykstra)
Subject: Re: Trapping sendmail errors (with eval?)
Message-Id: <fedb623e.0110041727.17799681@posting.google.com>

nobull@mail.com wrote in message news:<u9g08zxp38.fsf@wcl-l.bham.ac.uk>...

> That does not look like a Perl error.  That looks like STDOUT from
> sendmail. What makes you believe that you Perl script is crashing?
> 
> >   I've tried using eval to trap the error, but I can't get it to
> > work.
> 
> What makes you believe that there is an error to trap?
> 

Thanks for your reply.
You're correct, it is a sendmail error message, not a perl error.  My
confusion is with the fact that my perl program should continue
looping, trying X number of times to resend the message.   Instead of
detecting that there was an error from sendmail, however, the perl
script just dies.

Thanks,

   Bill


------------------------------

Date: 4 Oct 2001 20:23:33 -0700
From: filippomj@netscape.net (Mike Filippo)
Subject: Uninstall under Windows ME
Message-Id: <ad3e516c.0110041923.1ef0bbab@posting.google.com>

I've installed Perl 5.6 on an ME system. There is no entry in the
Add/Remove programs, there is no uninstall.bat file, and the Uninstall
entry in the FAQ is null. Can anyone tell me how to uninstall it?
Thanks.


------------------------------

Date: Fri, 05 Oct 2001 07:03:02 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: Uninstall under Windows ME
Message-Id: <Xns91311EF43535Erock13com@64.8.1.227>

Mike Filippo
<news:ad3e516c.0110041923.1ef0bbab@posting.google.com>: 

> I've installed Perl 5.6 on an ME system. There is no entry in
> the Add/Remove programs, there is no uninstall.bat file, and
> the Uninstall entry in the FAQ is null. Can anyone tell me how
> to uninstall it? Thanks.

Why on earth do you want to uninstall it?

Did you use ActivePerl? Mine put an entry in the Remove programs 
applet in the Control Panel. Otherwise, I suppose you have to do it 
manually.

-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


------------------------------

Date: Fri, 5 Oct 2001 03:08:03 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: using secure cgi space?
Message-Id: <slrn9rq90j.dmg.efflandt@typhoon.xnet.com>

On Thu, 4 Oct 2001, Nick Robinson <nick@cheesypeas.demon.co.uk> wrote:
> Can anyone point me to a good site on using cgi in a secure area? I'm
> having a few strange problems, such as env(remote_host) not returning a
> value in the secure area.

That probably has nothing to do with the secure space (or Perl).  Many
webservers are simply configured NOT to resolve REMOTE_HOST to save time,
so you need to do it yourself as demonstrated by this simple example:

#!/usr/bin/perl -w
use Socket;
my $ip = $ENV{REMOTE_ADDR};
my $host = gethostbyaddr(inet_aton($ip), AF_INET);
print "Content-type: text/plain\n\n",
"$ip ", ($host) ? "is $host\n" : "has no name\n";

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


------------------------------

Date: 4 Oct 2001 18:20:04 -0700
From: tana@acedsl.com (Tana)
Subject: what am I doing wrong ?
Message-Id: <4294f74d.0110041720.2afc78bc@posting.google.com>

I have a simple perl script like this:
#!/usr/bin/perl
use CGI;

$cgi=new CGI;
print $cgi->header();

print "User ID: $user_id";


And I call the script from internet browser like this:
http://hepek.com/cgi-bin/test.pl?user_id=100

I would expect to see a value for user_id (100) as a result, but value is emty.
All I see is "User ID: ".

what am I doing wrong?


------------------------------

Date: Thu, 04 Oct 2001 18:35:28 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: what am I doing wrong ?
Message-Id: <3BBD0E60.328C80A1@vpservices.com>

Tana wrote:
> 
> I have a simple perl script like this:


> #!/usr/bin/perl
> use CGI;

You should add warnings and strict to the start of your program,
otherwise you won't know when something goes wrong.

> 
> $cgi=new CGI;
> print $cgi->header();
> 
> print "User ID: $user_id";
>
> And I call the script from internet browser like this:
> http://hepek.com/cgi-bin/test.pl?user_id=100
> 
> I would expect to see a value for user_id (100) as a result, but value is emty.
> All I see is "User ID: ".

The CGI.pm module does not automatically create perl variables.  If you
want to access data from a URL or a form, you need to use the
$cgi->param() method, see the CGI docs.  In this case you need this
before your print statement:

    my $user_id = $cgi->param('user_id') or 'No User Id Supplied';

-- 
Jeff



------------------------------

Date: Thu, 4 Oct 2001 02:31:24 -0700
From: benhopkins@mindspring.com
Subject: Re: Why does if statement not work ?
Message-Id: <c9ahp9.ds3.ln@127.0.0.1>

Nick Blake <nick.blake@qr.com.au> wrote:
> I tried but still receiving a error.

> Can't find string terminator "'" anywhere before EOF at roky.pl line 10.

> while ( <> ){

> ($path, $who, $acl) = split(/,/, $_);
> chomp $acl;

>  $length = length( $path );

> $newpath = substr($path, -1, $length);

> if ( $newpath eq '\'){ print "yes it is\n" }
the backslash escapes the closing apostrophe.
> }




------------------------------

Date: Thu, 04 Oct 2001 21:37:54 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Yet another fork question
Message-Id: <3BBD0EF2.ACB6E744@earthlink.net>

Mr. Sunblade wrote:
> 
> Benjamin Goldberg wrote:
[snip]
> > Like I said, signal handlers are really funky things... in general,
> > if you can, try and avoid having to mess with them.
> 
> I read Lincoln Stein's "Network Programming with Perl" book and that's
> how he set up the signal handlers for client/server apps (i.e. with
> $SIG{CHLD}). After I saw that, I started getting into the habit of
> using it everywhere I used fork.  Perhaps it was a case of "give
> someone a hammer...".
> 
> Thanks for the tips.  I'll have to break this habit now (for non
> client/server apps, anyway). :)

Indeed.  A forking server is one of those places where you just about
*need* to have a signal handler.  This is because the server spends it's
time in accept(), gets a connection, forks a child to handle that
connection, and then goes back into accept() ... there isn't any
"obvious" place to put a call to wait or waitpid, especially since the
server process will probably be in accept() at the time the child dies.

You *could* of course have:
while( my $client = $socket->accept() ) {
    1 while( -1 != waitpid( -1, &WNOHANG );
    if( my $pid = fork ) {
    .....
}

Which is *almost* as good as a signal handler, but zombies do accumulate
during the accept() call, and even though they're mostly harmless, it's
not good style.

> I also welcome any other comments (from anyone) on the subject of
> signal handlers.

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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 1875
***************************************


home help back first fref pref prev next nref lref last post