[23286] in Perl-Users-Digest
Perl-Users Digest, Issue: 5506 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 15 14:05:48 2003
Date: Mon, 15 Sep 2003 11:05:10 -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 Mon, 15 Sep 2003 Volume: 10 Number: 5506
Today's topics:
Re: closed filehandle <samj@austarmetro.com.au>
Re: closed filehandle <tony_curtis32@yahoo.com>
Re: closed filehandle <samj@austarmetro.com.au>
Re: dbm problem HELP! <noreply@gunnar.cc>
Re: Direct experience of text manipulation in Perl/TCL? (Anno Siegel)
Re: equivalent of php function decbin (Thomas Theakanath)
Re: How To activate command line history in debugger? (Peter Scott)
importing a hash from package <cyberjeff@sprintmail.com>
Re: importing a hash from package <grazz@pobox.com>
Re: importing a hash from package <cyberjeff@sprintmail.com>
kill command in a perl script (Hugh Kang)
Need a bit of help with threads programming (David Morel)
Re: Need a bit of help with threads programming <ThomasKratz@REMOVEwebCAPS.de>
need DBD::ODBC help (Andrew Burton)
Re: Need help on split-function <flavell@mail.cern.ch>
Re: Perl DBMS (Anno Siegel)
Re: system command question (Anno Siegel)
Re: THOSE ANNOYING POP UP MESSAGES. <xaonon@hotpop.com>
Re: Tring to kill my kids, but they are stuborn little <eric@dmcontact.com>
Re: Tring to kill my kids, but they are stuborn little <eric@dmcontact.com>
Re: Tring to kill my kids, but they are stuborn little <grazz@pobox.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 15 Sep 2003 16:30:51 GMT
From: "Sam" <samj@austarmetro.com.au>
Subject: Re: closed filehandle
Message-Id: <3f65e938@news.comindico.com.au>
"Tintin" <me@privacy.net> wrote in message
news:bk3u2l$n3ch2$1@ID-172104.news.uni-berlin.de...
>
> "Sam" <samj@austarmetro.com.au> wrote in message
> news:3f6568df$1@news.comindico.com.au...
> >
> > "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> > news:tcc9b.9890$1D5.4139@nwrddc02.gnilink.net...
> > > Sam wrote:
> > > > the file name is avg and it is located at /home/<username>/data
> > > > directory
> > >
> > > Then why are you trying to open
> > > home/user/data/avg
> > > instead of
> > > /home/user/data/avg
> > >
> > > Or did you make sure that your CWD is the root directory?
> > > At least I didn't see any code for that anywhere in your previous code
> > > samples.
> > >
> > > jue
> > >
> > >
> >
> > I really need help to understand this. as I have been reading, you need
a
> > file handler (DATA) attach to it the file name and pass that to the sub
> open
> > inorder to read the file's line by line in the variable $_. what I am
> > missing?
>
> The correct path to the file.
>
>
how do I work out that correct path to this file?
I tried
/home/user/data/avg
home/user/data/avg
/data/avg
data/avg
I am logged in as usr$
------------------------------
Date: Mon, 15 Sep 2003 11:36:22 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: closed filehandle
Message-Id: <87ad96nh4p.fsf@limey.hpcc.uh.edu>
>> On Mon, 15 Sep 2003 16:30:51 GMT,
>> "Sam" <samj@austarmetro.com.au> said:
> "Tintin" <me@privacy.net> wrote in message
>> The correct path to the file.
>>
> how do I work out that correct path to this file? I
> tried /home/user/data/avg home/user/data/avg /data/avg
> data/avg I am logged in as usr$
Only you can know where the file is on your system. Go
into the directory where the file lives and do "pwd".
If you don't know where the file is, how do you expect to
be able to write a program to open it?
------------------------------
Date: Mon, 15 Sep 2003 17:54:07 GMT
From: "Sam" <samj@austarmetro.com.au>
Subject: Re: closed filehandle
Message-Id: <3f65fcbe@news.comindico.com.au>
"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:87ad96nh4p.fsf@limey.hpcc.uh.edu...
> >> On Mon, 15 Sep 2003 16:30:51 GMT,
> >> "Sam" <samj@austarmetro.com.au> said:
>
> > "Tintin" <me@privacy.net> wrote in message
>
> >> The correct path to the file.
> >>
> > how do I work out that correct path to this file? I
> > tried /home/user/data/avg home/user/data/avg /data/avg
> > data/avg I am logged in as usr$
>
> Only you can know where the file is on your system. Go
> into the directory where the file lives and do "pwd".
>
> If you don't know where the file is, how do you expect to
> be able to write a program to open it?
boxname:/home/username/data# ls
avg
boxname:/home/username/data# pwd
/home/username/data
boxname:/home/username/data#
it is working now, for a reason I still don't understand why. it must be
something with the xemacs set-up. for the fact the file name change from
xxx.plx to xxx.pl
I am puzzled.
------------------------------
Date: Mon, 15 Sep 2003 17:02:38 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: dbm problem HELP!
Message-Id: <bk4kh9$otal6$1@ID-184292.news.uni-berlin.de>
Tom wrote:
> I can write to, close aand reopen a dbm file with hashes of hasjed
> of hashes and everything is OK.
No you can't. A simple DBM file only stores keys and values, not
complex data structures.
> Data I write is read back just fine.
Sure. The problem is that what you read is not what you think you
read.
> However, when I run the program again later on and use the same
> exact code to reopen the dbm, al the data is gone.
It was never stored in the DBM file.
> Here is a snippet of what I am doing:
>
> dbmopen (%nd,$ndbfile,0666) || die "Can't dbmopen $ndbfile: $!";
>
> $stk = "ABC";
> $datecode = "20030914";
> $druntime = "700";
> $data = "12345";
>
> $nd{$stk}{$datecode}{$druntime}{Data} = $data;
At this point, you have the hash %nd in memory containing the key
'ABC' and a _hash reference_ as the value. However, the DBM file does
not save the hash reference; it just saves a _string_ that looks
something like 'HASH(0x1555198)'.
<snip>
> Apparently, there is a problem accessing the dbm file, though it is
> there.
No, that's not the problem. (See above.)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 15 Sep 2003 15:43:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Direct experience of text manipulation in Perl/TCL?
Message-Id: <bk4mmd$1uv$2@mamenchi.zrz.TU-Berlin.DE>
Helgi Briem <f_baggins80@hotmail.com> wrote in comp.lang.perl.misc:
> On 11 Sep 2003 15:06:57 GMT, Abigail <abigail@abigail.nl> wrote:
>
> >Processing text in Perl is a pain. It lacks decent parsing tools
> >(yeah, there's perl6 vaporware...), all it has is a slightly beefed
> >up sed. Man, I could tell you about the times I couldn't do
> >something simple in Perl, and had to use a gazillion badly
> >documented, buggy modules to get it done.
> >
> >Abigail
>
> You're an evil, evil person, Abigail.
Of course she is! That's why we love her.
Anno
------------------------------
Date: 15 Sep 2003 09:43:36 -0700
From: thomastk@hotmail.com (Thomas Theakanath)
Subject: Re: equivalent of php function decbin
Message-Id: <78b857d2.0309150843.e771a7@posting.google.com>
Thanks much. As usual, there are multiple ways to do this, per the
FAQ, using sprintf and Vector. My corrected routine would be the
following:
sub decbin {
my $num=shift;
my $str = unpack("B*",pack("N",$num));
return $str;
}
Thomas.
------------------------------
Date: Mon, 15 Sep 2003 15:04:12 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: How To activate command line history in debugger?
Message-Id: <Mxk9b.964662$3C2.21765412@news3.calgary.shaw.ca>
In article <bjhde7$g22$07$1@news.t-online.com>,
Kurt Kronschnabl <k.kronschnabl_nospm_@ica-intercom-akademie.de> writes:
>does anybody know how to enable the command line history in the debugger?
>
>Under Suse 8.2 is it already active. Not under Knoppix 3.1/3.2.
>
>I am a newbie in perl and don't understand the explanation in "man
>perldeb" to install Term::ReadKey and Term::Readline. I tried to create
>the file .perldb in ~ with the content
>use Term::ReadKey;
>use Term::Readline;
>but this does not enable the history feature. BTW in the perl lib dirs
>is a ReadLine.pm but no a ReadKey.
You need to install the missing module. Become root and type
perl -MCPAN -e 'install Term::ReadKey'
If you have never run CPAN.pm before there will be a slew of questions
to answer that should be self explanatory.
Without this module Perl has no mechanism to intercept the arrow key
presses and interpret them as requests to traverse the command line history.
--
Peter Scott
http://www.perldebugged.com
------------------------------
Date: Mon, 15 Sep 2003 13:46:43 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: importing a hash from package
Message-Id: <3F65C3ED.C21C579D@sprintmail.com>
I'm sure this is easy, but I'm not finding it...
I have a package with a heash in it:
package VARIABLES;
my %HASH;
$HASH{a}='a';
$some_scalar='some_scalar'
...
I want to refer to that hash elsewhere.
I know I can do this:
my $local_some_scalar=VARIABLE::$some_scalar;
But, how do I get at HASH? Do I have to write a reference to it in
package VARIABLES?
Cheers,
Jeff
------------------------------
Date: Mon, 15 Sep 2003 14:38:54 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: importing a hash from package
Message-Id: <2ak9b.4549$Kt4.1019@nwrdny02.gnilink.net>
Jeff Thies <cyberjeff@sprintmail.com> wrote:
> package VARIABLES;
>
> my %HASH;
> $HASH{a}='a';
>
> $some_scalar='some_scalar'
>
> ...
>
> I want to refer to that hash elsewhere.
>
> I know I can do this:
>
> my $local_some_scalar=VARIABLE::$some_scalar;
^^^^^^^^^^^^^^^^^^^^^^
That's not quite right.
> But, how do I get at HASH? Do I have to write a reference to it
> in package VARIABLES?
The difference is between lexical (my) variables, which you can't
use outside the scope where they were declared, and package variables,
which are global.
You can use our() to declare package variables.
our %HASH; # %VARIABLES::HASH
Is that what you were after?
--
Steve
------------------------------
Date: Mon, 15 Sep 2003 15:08:51 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: Re: importing a hash from package
Message-Id: <3F65D72C.6FB6DAEB@sprintmail.com>
Steve Grazzini wrote:
>
> Jeff Thies <cyberjeff@sprintmail.com> wrote:
> > package VARIABLES;
> >
> > my %HASH;
> > $HASH{a}='a';
> >
> > $some_scalar='some_scalar'
> >
> > ...
> >
> > I want to refer to that hash elsewhere.
> >
> > I know I can do this:
> >
> > my $local_some_scalar=VARIABLE::$some_scalar;
> ^^^^^^^^^^^^^^^^^^^^^^
oops!
>
> That's not quite right.
>
> > But, how do I get at HASH? Do I have to write a reference to it
> > in package VARIABLES?
>
> The difference is between lexical (my) variables, which you can't
> use outside the scope where they were declared, and package variables,
> which are global.
>
> You can use our() to declare package variables.
>
> our %HASH; # %VARIABLES::HASH
>
> Is that what you were after?
Yes, thanks!
Jeff
>
> --
> Steve
------------------------------
Date: 15 Sep 2003 10:13:24 -0700
From: skang@leaguedata.com (Hugh Kang)
Subject: kill command in a perl script
Message-Id: <257137ea.0309150913.11f08d49@posting.google.com>
I just started learning Perl and I am trying to do followings;
ps -ef | grep java >pidfile
In pidfile, there are 3 PIDs for weblogic processes.
root 1769 1758 TS 0 0 17:55:26 vt02 44:38
/opt/java2-1.3.1/bin/./../bin/x86at/native_threads/java -Xms512m
-Xmx512m -Dweb
root 27464 27453 TS 29 0 09:15:55 vt04 91:55
/opt/java2-1.3.1/bin/./../bin/x86at/native_threads/java -Xms1024m
-Xmx1024m -Dw
root 27533 27522 TS 49 0 09:21:45 vt03 2:35
/opt/java2-1.3.1/bin/./../bin/x86at/native_threads/java -Xms32m
-Xmx200m -Dwebl
What I want is get the largest PID which is 27533 in this case, and
then
kill -3 the PID.
So I made a simple one for this:
#!/usr/bin/perl
#
# This is a test script to get wls managed server pid
#
#
open(JAVAPIDS,"pidfile") or die "can't open input file:$!\n";
$pidcnt=0;
while($line=<JAVAPIDS>) {
# ($user,$pid1,$pid2,$it4,$it5,$it6,$it7,$it8,$it9,$it10,$it11,$it12,$it13,$it14,$it15)=split("
",$line);
($user,$pid1)=split(" ",$line);
$pidfile{$pid1}=$pid1;
$pid_comp[$pidcnt]=$pidfile{$pid1};
# print "pid$pidcnt : $pid_comp[$pidcnt] \n";
if ($pidcnt gt 0) {
if ($pid_comp[0] < $pid_comp[$pidcnt]) {
$pid_comp[0] = $pid_comp[$pidcnt];
}
}
$pidcnt++;
}
print "pidcnt : $pidcnt \n";
print "Largest PID for java is : $pid_comp[0] \n";
------------------------------------------
Q1) How do I do 'kill -3 $pid_comp[0] in this script?
Q2) Is there any way that I can do the followings:
In a Unix script,
ps -ef |grep java >pidfile
./perl_script
...
...
kill -3 $pid_comp[0]
Q3) Any other way to get what I want?
Can anyone help me out with this issue please?
Many thanks in advance!
Hugh
------------------------------
Date: 15 Sep 2003 08:48:13 -0700
From: altalingua@hotmail.com (David Morel)
Subject: Need a bit of help with threads programming
Message-Id: <60c4a7b1.0309150748.39d678de@posting.google.com>
Hi all,
I need a subroutine that reads the next line in an open file.
Ordinarily this would be a trivial subroutine... you just read a line
off of a filehandle.
However, I need this subroutine to be threads-safe. That is, I plan on
having many threads be using this subroutine, and I need to make sure
that it is always reading the next line no matter what thread is using
it.
The problem I came across is that you are not allowed to share
filehandles (GLOBS). So how would I go about implementing this
routine?
Thanks,
David Morel
------------------------------
Date: Mon, 15 Sep 2003 18:11:12 +0200
From: "Thomas Kratz" <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Need a bit of help with threads programming
Message-Id: <3f65e514.0@juno.wiesbaden.netsurf.de>
DQoiRGF2aWQgTW9yZWwiIDxhbHRhbGluZ3VhQGhvdG1haWwuY29tPiB3cm90ZSBpbiAgbmV3czo2
MGM0YTdiMS4wMzA5MTUwNzQ4LjM5ZDY3OGRlQHBvc3RpbmcuZ29vZ2xlLmNvbS4uLg0KDQo+IEhp
IGFsbCwNCj4gDQo+IEkgbmVlZCBhIHN1YnJvdXRpbmUgdGhhdCByZWFkcyB0aGUgbmV4dCBsaW5l
IGluIGFuIG9wZW4gZmlsZS4NCj4gT3JkaW5hcmlseSB0aGlzIHdvdWxkIGJlIGEgdHJpdmlhbCBz
dWJyb3V0aW5lLi4uIHlvdSBqdXN0IHJlYWQgYSBsaW5lDQo+IG9mZiBvZiBhIGZpbGVoYW5kbGUu
DQo+IA0KPiBIb3dldmVyLCBJIG5lZWQgdGhpcyBzdWJyb3V0aW5lIHRvIGJlIHRocmVhZHMtc2Fm
ZS4gVGhhdCBpcywgSSBwbGFuIG9uDQo+IGhhdmluZyBtYW55IHRocmVhZHMgYmUgdXNpbmcgdGhp
cyBzdWJyb3V0aW5lLCBhbmQgSSBuZWVkIHRvIG1ha2Ugc3VyZQ0KPiB0aGF0IGl0IGlzIGFsd2F5
cyByZWFkaW5nIHRoZSBuZXh0IGxpbmUgbm8gbWF0dGVyIHdoYXQgdGhyZWFkIGlzIHVzaW5nDQo+
IGl0Lg0KPiANCj4gVGhlIHByb2JsZW0gSSBjYW1lIGFjcm9zcyBpcyB0aGF0IHlvdSBhcmUgbm90
IGFsbG93ZWQgdG8gc2hhcmUNCj4gZmlsZWhhbmRsZXMgKEdMT0JTKS4gU28gaG93IHdvdWxkIEkg
Z28gYWJvdXQgaW1wbGVtZW50aW5nIHRoaXMNCj4gcm91dGluZT8NCg0KV2hhdCBhYm91dCBoYXZp
bmcgb25lIHRocmVhZCByZWFkaW5nIHRoZSBmaWxlIGFuZCBoYXZpbmcgYSBzaGFyZWQgKFNlZSB0
aHJlYWRzOjpzaGFyZWQgKSBzY2FsYXIgb3IgYXJyYXkgZm9yIHN0b3Jpbmcgb25lIG9yIG1vcmUg
bGluZXMgb2YgdGhlIGZpbGU/IEhhdmUgYSBsb29rIGF0IGxvY2soKSBhbmQgVGhyZWFkOjpTZW1h
cGhvcmUgb3IgcGVyaGFwcyBiZXR0ZXIgVGhyZWFkOjpRdWV1ZSBmb3IgYWNjZXNzaW5nIHRoZSBz
aGFyZWQgZGF0YSBmcm9tIG90aGVyIHRocmVhZHMuDQoNCllvdSBjYW4gZ2V0IGFuIG92ZXJ2aWV3
IGluOg0KDQpwZXJsZG9jIHBlcmx0aHJ0dXQNCg0KVGhvbWFzDQo=
------------------------------
Date: 15 Sep 2003 16:49:46 GMT
From: tuglyraisin@aol.commcast (Andrew Burton)
Subject: need DBD::ODBC help
Message-Id: <20030915124946.03231.00000839@mb-m11.aol.com>
I'm trying to get a Linux box, with RedHat 8 and Perl 5.8.0, to connect with an
AS400 machine through ODBC. I'm fairly sure I can get it to connect, because I
don't get an error until I try to use $db->prepare(). I will post the code and
errors below. I get two errors, but I am fairly sure the second error is a
result of the first. My main questions, to anyone who has written a Perl
script/program that connects to an IBM machine, are three-fold:
1. What am I doing wrong?
2. Should I be using DBD::DB2?
3. If so, what kind of drivers do I need to use DBD::DB2?
Thanks for any help, as me and my boss have spent a good bit of time digging
through IBM sites, the Usenet, and the web. Thanks. Here's the bit of code
I'm using to "prototype" a connection:
[code]
#!/usr/bin/perl -w
use strict;
use DBI;
my $db = DBI->connect('dbi:ODBC:AS400', 'myid', 'mypassword') or die
$DBI::errstr;
my $out = $db->prepare("SELECT * FROM CD02 WHERE CD02_INSTRNO = '4110'");
$out->execute() or die $DBI::errstr;
while (my @lala = $out->fetchrow_array()) {
foreach my $la (@lala) {
print "$la\t";
}
print "\n";
}
exit;
[/code]
...and here are the errors I get:
[errors]
DBD::ODBC::db prepare failed: [unixODBC][IBM][iSeries Access ODBC Driver][DB2
UDB] (SQL-HY000)
[unixODBC][IBM][iSeries Access ODBC Driver][DB2 UDB] (SQL-42S02)(DBD:
st_prepare/SQLPrepare err=-1) at ./odbctest line 8.
Can't call method "execute" on an undefined value at ./odbctest line 9.
[/errors]
Andrew Burton - tuglyraisin at aol dot com
Felecia Station on Harvestgain - http://www.darkbeast.com/
"I often question my sanity; it has yet to give me a straight answer."
"And if you're bored, it's because... you're boring." - Matt Drudge
------------------------------
Date: Mon, 15 Sep 2003 14:37:41 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Need help on split-function
Message-Id: <Pine.LNX.4.53.0309151431350.7424@lxplus067.cern.ch>
On Mon, Sep 15, Helgi Briem inscribed on the eternal scroll:
> Comp.lang.perl is extinct. It doesn't exist except on
> misconfigured servers. You should never ever post
> to it.
Having a regular posting on comp.lang.perl to warn people that it
doesn't really exist (and with an authoritative link to the original
control message which should have rmgroup-ed it) would seem to be a
self-contradictory thing to do, but I'm not sure how else the message
is ever going to get out. :-{
------------------------------
Date: 15 Sep 2003 13:31:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl DBMS
Message-Id: <bk4f0d$reu$1@mamenchi.zrz.TU-Berlin.DE>
ge0rge <ge0rge@Talk21.com> wrote in comp.lang.perl.misc:
> <OT>
>
> "Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
> news:Pine.LNX.4.53.0309130126160.5502@lxplus002.cern.ch...
[top-posting and killfiles]
> BTW, I think the whole idea of a killfile is another OTT response to
> something not worth a second thought... but then again there's no accounting
> for what people feel passionate about.
>
> Anyway, I shall do as suggested by another poster - when in Rome ... ('cos
> top posters drive me nuts (well, rarely!)).
>
> Now, time for me to shut up and start lurking awhile in this NG until I have
> something worthwhile to ask or say!
Until then I have a suggestion for you. Try reading this group the way
a question-answering regular does. That means, look at *every* posting
close enough so you can decide whether there is a question in there you
may want to answer. Do that for, say, a week (not months and years, like
many regulars), not actually answering, just reading everything until you
know what it's about.
Then, if you are still of the opinion that insistence in a readable
posting style is "over the top", we may be inclined to listen to your
arguments.
Anno
------------------------------
Date: 15 Sep 2003 15:17:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: system command question
Message-Id: <bk4l5q$1uv$1@mamenchi.zrz.TU-Berlin.DE>
Chris Mattern <syscjm@gwu.edu> wrote in comp.lang.perl.misc:
> Andreas Kahari wrote:
> > In article <3F61EB8C.8000604@gwu.edu>, Chris Mattern wrote:
> >
> >>Himal wrote:
> >>
> >>>I there a reason why a command will not work if i do system "$cmd &>
> >>>xyz.log" even though it works if I do system "$cmd"
[...]
> Ah, OK, I thought it used the user's shell. OK, then,
> system "$cmd >xyz.log 2>&1" should be the answer, assuming
> the OP is on a Unix system (which seems logical, since he's
> trying to use csh syntax).
Except that he isn't. "$cmd >& xyz.log" would be csh syntax.
"$cmd &> xyz.log" is neither here nor there.
Anno
------------------------------
Date: 15 Sep 2003 16:11:42 GMT
From: Xaonon <xaonon@hotpop.com>
Subject: Re: THOSE ANNOYING POP UP MESSAGES.
Message-Id: <slrnbmc3mb.1rk.xaonon@xaonon.local>
Ned i bach <bif9b.1019$fX1.160103@newsfep2-gui.server.ntli.net>, NOMORE
<zxvsdgs@freeuk.com> teithant i thiw hin:
> Want to stop those annoying pop up messages
> Without spending $30+ on software.
> I will show you how http://savea4tune.net/nomorepopups.htm
You misspelled <http://www.mozilla.org/>.
--
Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
http://xaonon.dyndns.org/: Guaranteed content-free since 1999. No refunds.
"Remember, kids! Don't try to stop Russians from picking mushrooms! Or
they'll nuke you!" -- James "Kibo" Parry, in alt.religion.kibology
------------------------------
Date: Mon, 15 Sep 2003 15:08:15 GMT
From: bob <eric@dmcontact.com>
Subject: Re: Tring to kill my kids, but they are stuborn little bastards!
Message-Id: <3F65D5F3.9080705@dmcontact.com>
Hi,
You know you really kind of hit the nail on the head. The exit or die,
don't kill the child. I do want to be able to have the child accept a
command though, so other than not dieing when it is done, it is doing
what I want.
Thanks for your post,
Eric
Heinrich Mislik wrote:
> In article <3F64B2EB.3E7E39CA@dmcontact.com>, eric@dmcontact.com says...
>
> I didn' test this, but please consider the following:
>
> [code snipped]
>
>
>>while (my $connection = $listen_socket->accept()) {
>>
>> my $pid;
>> if (!defined($pid = fork)) {
>> logmsg "cannot fork: $!";
>>
>> }elsif ($pid) {
>> logmsg "begat $pid";
>> }else{
>> # else i'm the child -- go spawn
>> print $connection "Command?";
>> while ( <$connection> ){
>>
>> if (/quit|exit/i) {
>>last; }
>
>
> This gets the child out of the 'while ( <$connection> )' loop, but leaves it in the 'while (my $connection = $listen_socket->accept())' loop. So the child never dies, but listens for new connections.
> Entering the command dieT at your prompt should really kill the child.
>
>
>
>> elsif (/closeme/i )
>>{$connection->close(); }
>> elsif (/date|time/i) { printf $connection "%s\n",
>>scalar localtime; }
>> elsif (/who/i ) { print $connection `who
>>2>&1`; }
>> elsif (/dienow/i ) { alarm
>>2; }
>> elsif (/dieT/i ) {
>>die; }
>
>
> dieT is a typo, isn't it.
>
> hth.
>
------------------------------
Date: Mon, 15 Sep 2003 15:12:57 GMT
From: bob <eric@dmcontact.com>
Subject: Re: Tring to kill my kids, but they are stuborn little bastards!
Message-Id: <3F65D70D.6@dmcontact.com>
Hi,
This is another example I did = cut from examples.
This one, works, but when I exit the whole thing including the parent die!
#!/usr/bin/perl -w
use strict;
use POSIX ();
use POSIX 'WNOHANG';
#use POSIX ":sys_wait_h";
use FindBin ();
use File::Basename ();
use File::Spec::Functions;
use Net::hostent;
use Carp;
use Data::Dumper;
use Asiadebit;
$|=1;
sub spawn; # forward declaration
sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }
#use IO::Socket::INET;
use IO::Socket;
my $listen_socket = IO::Socket::INET->new(LocalPort => 1081,
LocalAddr => '127.0.0.1',
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1 )
or die "can make a tcp server on port 1080 $!";
# make the daemon cross-platform, so exec always calls the script
# itself with the right path, no matter how the script was invoked.
my $script = File::Basename::basename($0);
my $SELF = catfile $FindBin::Bin, $script;
# POSIX unmasks the sigprocmask properly
my $sigset = POSIX::SigSet->new();
my $action = POSIX::SigAction->new('sigHUP_handler',
$sigset,
&POSIX::SA_NODEFER);
my $action_alrm = POSIX::SigAction->new('sigALRM_handler',
$sigset,
&POSIX::SA_NODEFER);
POSIX::sigaction(&POSIX::SIGHUP, $action);
POSIX::sigaction(&POSIX::SIGALRM, $action_alrm);
sub sigHUP_handler {
print "got SIGHUP\n";
exec($SELF, @ARGV) or die "Couldn't restart: $!\n";
}
sub sigALRM_handler {
print "got ALARM timeout\n";
}
$SIG{CHLD} = \&REAPER_NEW;
sub REAPER {
$SIG{CHLD} = \&REAPER; # loathe sysV
my $waitedpid = wait;
logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
}
sub REAPER_NEW {
logmsg "got - @_\n";
my $wpid = undef;
while ($wpid = waitpid(-1,WNOHANG)>0) {
logmsg "reaped $wpid" . ($? ? " with exit $?" : '');
}
}
code();
sub code {
print "PID: $$\n";
print "ARGV: @ARGV\n";
open (DIED, ">>/var/log/daemon_log") or warn "$!";
my $c = 0;
#while (++$c) {
# sleep 2;
# my $bob = `w`;
# print DIED "$bob\n";
#print "$c\n";
#}
print "[Server $0 accepting clients]\n";
while (my $connection = $listen_socket->accept()) {
$connection->autoflush(1);
print $connection "Welcome to $0; type help for command list.\n";
my $hostinfo = gethostbyaddr($connection->peeraddr);
printf "[Connect from %s]\n", $hostinfo->name || $connection->peerhost;
print $connection "Command? ";
spawn sub {
while ( <$client>) {
next unless /\S/; # blank line
if (/quit|exit/i) { last; }
elsif (/date|time/i) { printf $connection "%s\n", scalar
localtime; }
elsif (/who/i ) { print $connection `who 2>&1`;
}
elsif (/dienow/i ) { alarm 2; }
elsif (/dieT/i ) { die; }
elsif (/spawnme/i ) { spawn \&code(); }
elsif (/cleanme/i ) { REAPER(); }
elsif (/debug/i ) { print Dumper($client);}
elsif (/spawn/i) {
spawn sub {
sleep 1;
print "Hello there, it's now ", scalar localtime, "\n";
sleep 3;
print "EXITING\n";
#exec '/usr/games/fortune'
# or confess "can't exec fortune: $!";
};
}
elsif (/alarmtest/i) { test_alarm(); }
elsif (/motd/i ) { print $client `cat /etc/motd 2>&1`; }
elsif (/AUTH/i ) { print do_auth($_) }
else {
print $client "Commands: quit date who cookie motd\n";
print DIED "Commands: quit date who cookie motd\n";
}
### print the prompt again regardless of input...
print $connection "Command? ";
}
close $connection;
} ## end 2nd while
} ### end code sub
} ## end 1st while
sub test_alarm {
alarm 5;
while (1>0){
sleep 1;
print "$_ to go";
}
}
sub spawn {
my $coderef = shift;
#local $SIG{CHLD} = \&REAPER;
#sub REAPER {
# $SIG{CHLD} = \&REAPER; # loathe sysV
# my $waitedpid = wait;
# logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
#}
unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE') {
confess "usage: spawn CODEREF";
}
my $pid;
if (!defined($pid = fork)) {
logmsg "cannot fork: $!";
return;
} elsif ($pid) {
logmsg "begat $pid";
return; # i'm the parent
}
# else i'm the child -- go spawn
#open(STDIN, "<$client") || die "can't dup client to stdin";
#open(STDOUT, ">$client") || die "can't dup client to stdout";
#open(STDERR, ">&STDOUT") || die "can't dup stdout to stderr";
#### Works but we need the connected socket object!!!!
#STDIN->fdopen($client,"r") || die "can't dup client to stdin";
#STDOUT->fdopen($client,"w") || die "can't dup client to stdout";
#STDERR->fdopen($client,"w") || die "can't dup stdout to stderr";
exit &$coderef();
}
Heinrich Mislik wrote:
> In article <3F64B2EB.3E7E39CA@dmcontact.com>, eric@dmcontact.com says...
>
> I didn' test this, but please consider the following:
>
> [code snipped]
>
>
>>while (my $connection = $listen_socket->accept()) {
>>
>> my $pid;
>> if (!defined($pid = fork)) {
>> logmsg "cannot fork: $!";
>>
>> }elsif ($pid) {
>> logmsg "begat $pid";
>> }else{
>> # else i'm the child -- go spawn
>> print $connection "Command?";
>> while ( <$connection> ){
>>
>> if (/quit|exit/i) {
>>last; }
>
>
> This gets the child out of the 'while ( <$connection> )' loop, but leaves it in the 'while (my $connection = $listen_socket->accept())' loop. So the child never dies, but listens for new connections.
> Entering the command dieT at your prompt should really kill the child.
>
>
>
>> elsif (/closeme/i )
>>{$connection->close(); }
>> elsif (/date|time/i) { printf $connection "%s\n",
>>scalar localtime; }
>> elsif (/who/i ) { print $connection `who
>>2>&1`; }
>> elsif (/dienow/i ) { alarm
>>2; }
>> elsif (/dieT/i ) {
>>die; }
>
>
> dieT is a typo, isn't it.
>
> hth.
>
------------------------------
Date: Mon, 15 Sep 2003 17:39:23 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Tring to kill my kids, but they are stuborn little bastards!
Message-Id: <fPm9b.4434$U41.1492@nwrdny01.gnilink.net>
bob <eric@dmcontact.com> wrote:
> This one, works, but when I exit the whole thing including the
> parent die!
> $SIG{CHLD} = \&REAPER_NEW;
>
> while (my $connection = $listen_socket->accept()) {
I already told you why this is happening.
When the child exits, SIGCHLD will interrupt the accept() system
call. Perl 5.8 installs %SIG handlers without SA_RESTART, and so
accept() fails when interrupted. (And then the parent falls out
of its loop and exits.)
--
Steve
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5506
***************************************