[29964] in Perl-Users-Digest
Perl-Users Digest, Issue: 1207 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 17 11:09:50 2008
Date: Thu, 17 Jan 2008 08:09:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 17 Jan 2008 Volume: 11 Number: 1207
Today's topics:
Calling binary from Perl prog and passing arguments <vinshalvi@gmail.com>
Re: Chat client/server print failed <zentara@highstream.net>
Help: Login FTP <openlinuxsource@gmail.com>
Re: Help: Login FTP <darthludi@gmail.com>
Re: Help: Login FTP <openlinuxsource@gmail.com>
Re: Help: Login FTP <rkb@i.frys.com>
Re: Help: Login FTP <rkb@i.frys.com>
Help: undefined symbol: strlcpy <openlinuxsource@gmail.com>
Re: Help: undefined symbol: strlcpy <openlinuxsource@gmail.com>
Re: Help: undefined symbol: strlcpy <ben@morrow.me.uk>
Re: In perl 5.10, is $needle ~~ @haystack binary search <g_m@remove-comcast.net>
Re: incorrect errno/perror with IO::socket->new <uri@stemsystems.com>
Re: incorrect errno/perror with IO::socket->new <brandon.mayfield@att.net>
Re: Shrink large file according to REG_EXP <bugbear@trim_papermule.co.uk_trim>
Re: Shrink large file according to REG_EXP <uri@stemsystems.com>
Re: Shrink large file according to REG_EXP <bugbear@trim_papermule.co.uk_trim>
Re: Wait for background processes to complete <pgodfrin@gmail.com>
Re: Wait for background processes to complete <simon.chao@fmr.com>
Re: Wait for background processes to complete <pgodfrin@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 17 Jan 2008 06:26:19 -0800 (PST)
From: vineet <vinshalvi@gmail.com>
Subject: Calling binary from Perl prog and passing arguments
Message-Id: <4f375943-9bfe-475b-8a1f-a48f8c42b5b6@j20g2000hsi.googlegroups.com>
Hi Experts,
I have sql interface which connects to oracle database. When I execute
sql, it connects to database and give prompt where user can type sql
statemets to be executed ... some thing like
$
$
$SQL;
SQL>
SQL>
SQL> select * from employee;
.......<display the sql result>.......
I wanted to write wrapper script over SQL interface and read a file
having SQL statement and passed it to SQL interface.
Can you please guide me how to start writing this.
Thanks,
VS
------------------------------
Date: Thu, 17 Jan 2008 15:56:30 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Chat client/server print failed
Message-Id: <vbuuo31ggmrikhktrsrl8guushk2sd3ktc@4ax.com>
On Wed, 16 Jan 2008 15:46:52 -0500, zentara <zentara@highstream.net>
wrote:
>On Tue, 15 Jan 2008 16:32:52 -0800 (PST), deadpickle
><deadpickle@gmail.com> wrote:
>
>>This is a chat client wrote in perl Gtk2. THe problem that I am
>>running into is that when you type and click send I get a "print() on
>>closed filehandle GEN0 at chat-client.pl line 332" error. This error
>>is the print statement in the send_msg_all sub. I cant figure out how
>>the file handle is closed and am wondering if anyone can see why. I'll
>>leave the server running for testing purposes.
>
>I'm sorry to say, that this complex set of scripts is a PITA to deal
>with.
>
>After fixing the many wordwrap problems, and host mismatches,
>I got to see your problem.
>
>It's too complex for me to see how to fix it, without alot of work.
>
>Simply put, you need a bi-directional client so the client can
>function properly. The way it is setup, your $conn only works
>for the first connection, then is closed. So you are printing to a
>closed socket. You need a bi-directional client, OR some loop
>that keeps the client alive switching between send and recv mode.
Hi, I quickly looked at it again, and saw where you closed the $conn
filehandle. This isn't a fix, but comment out these lines in your
client. This is where you are shutting down.
unless (defined($rv) && length $data) {
# This would be the end of file, so close the client
# delete $inbuffer{$server};
# delete $outbuffer{$server};
# delete $ready{$server};
# $select->remove($server);
# close $server;
next;
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
------------------------------
Date: Thu, 17 Jan 2008 23:17:32 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Help: Login FTP
Message-Id: <pan.2008.01.17.15.17.31.386497@gmail.com>
Hello,
I wanna write a script that it can login the FTP server and go to the
specific directory to get the file list and download files. But I don't
know how to pass the user name part and password part. The FTP server is
an anonymous server.
My question is: Are there any Perl modules than can help users login FTP
without password and user name? Furthermore, which modules can help me get
file lists like "ls -l" in FTP server?
Thank you very much~
Regards,
Amy Lee
------------------------------
Date: Thu, 17 Jan 2008 16:22:18 +0100
From: Peter Ludikovsky <darthludi@gmail.com>
Subject: Re: Help: Login FTP
Message-Id: <1200583365.481814@nntpcache01.si.eunet.at>
1) Go to http://search.cpan.org/
2) In the textbox enter "FTP"
3) Click on the first result
4) Read & meditate
Amy Lee wrote:
> Hello,
>
> I wanna write a script that it can login the FTP server and go to the
> specific directory to get the file list and download files. But I don't
> know how to pass the user name part and password part. The FTP server is
> an anonymous server.
>
> My question is: Are there any Perl modules than can help users login FTP
> without password and user name? Furthermore, which modules can help me get
> file lists like "ls -l" in FTP server?
>
> Thank you very much~
>
> Regards,
>
> Amy Lee
------------------------------
Date: Thu, 17 Jan 2008 23:40:52 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: Login FTP
Message-Id: <pan.2008.01.17.15.40.52.255450@gmail.com>
On Thu, 17 Jan 2008 16:22:18 +0100, Peter Ludikovsky wrote:
> 1) Go to http://search.cpan.org/
> 2) In the textbox enter "FTP"
> 3) Click on the first result
> 4) Read & meditate
>
> Amy Lee wrote:
>> Hello,
>>
>> I wanna write a script that it can login the FTP server and go to the
>> specific directory to get the file list and download files. But I don't
>> know how to pass the user name part and password part. The FTP server is
>> an anonymous server.
>>
>> My question is: Are there any Perl modules than can help users login FTP
>> without password and user name? Furthermore, which modules can help me get
>> file lists like "ls -l" in FTP server?
>>
>> Thank you very much~
>>
>> Regards,
>>
>> Amy Lee
Thanks your advice. However I've done this before I posted this article.
There are so many modules about FTP, I can't find what actually I need. So
could you tell me more details?
TIA.
Amy
------------------------------
Date: Thu, 17 Jan 2008 08:08:42 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Help: Login FTP
Message-Id: <912a41b2-6533-4734-9143-8125a4337b25@d70g2000hsb.googlegroups.com>
On Jan 17, 7:40 am, Amy Lee <openlinuxsou...@gmail.com> wrote:
> On Thu, 17 Jan 2008 16:22:18 +0100, Peter Ludikovsky wrote:
> > 1) Go tohttp://search.cpan.org/
> > 2) In the textbox enter "FTP"
> > 3) Click on the first result
> > 4) Read & meditate
>
> > Amy Lee wrote:
> >> Hello,
>
> >> I wanna write a script that it can login the FTP server and go to the
> >> specific directory to get the file list and download files. But I don't
> >> know how to pass the user name part and password part. The FTP server is
> >> an anonymous server.
>
> >> My question is: Are there any Perl modules than can help users login FTP
> >> without password and user name? Furthermore, which modules can help me get
> >> file lists like "ls -l" in FTP server?
>
> >> Thank you very much~
>
> >> Regards,
>
> >> Amy Lee
>
> Thanks your advice. However I've done this before I posted this article.
> There are so many modules about FTP, I can't find what actually I need. So
> could you tell me more details?
>
> TIA.
>
> Amy
http://search.cpan.org/~gbarr/libnet-1.22/Net/FTP.pm
------------------------------
Date: Thu, 17 Jan 2008 08:08:55 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Help: Login FTP
Message-Id: <dde5def8-03ce-458d-8f2b-9fd287ace406@v67g2000hse.googlegroups.com>
On Jan 17, 7:40 am, Amy Lee <openlinuxsou...@gmail.com> wrote:
> On Thu, 17 Jan 2008 16:22:18 +0100, Peter Ludikovsky wrote:
> > 1) Go tohttp://search.cpan.org/
> > 2) In the textbox enter "FTP"
> > 3) Click on the first result
> > 4) Read & meditate
>
> > Amy Lee wrote:
> >> Hello,
>
> >> I wanna write a script that it can login the FTP server and go to the
> >> specific directory to get the file list and download files. But I don't
> >> know how to pass the user name part and password part. The FTP server is
> >> an anonymous server.
>
> >> My question is: Are there any Perl modules than can help users login FTP
> >> without password and user name? Furthermore, which modules can help me get
> >> file lists like "ls -l" in FTP server?
>
> >> Thank you very much~
>
> >> Regards,
>
> >> Amy Lee
>
> Thanks your advice. However I've done this before I posted this article.
> There are so many modules about FTP, I can't find what actually I need. So
> could you tell me more details?
>
> TIA.
>
> Amy
http://search.cpan.org/~gbarr/libnet-1.22/Net/FTP.pm
------------------------------
Date: Thu, 17 Jan 2008 22:28:27 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Help: undefined symbol: strlcpy
Message-Id: <pan.2008.01.17.14.28.26.82604@gmail.com>
I am running into the error "undefined symbol: strlcpy" when trying to
install several Perl modules (YAML, XML:Parser, XML::Simple, etc.) on a RHEL 3.
From what I have read, it seems that strlcpy is a function that is included with BSD, Solaris, and OSX, but is not in the GNU C Library.
However, I was able to compile these applications on my old Red Hat Linux 8.0 system without any problems, so the strlcpy function must be available in some library. I just can figure out what it is or how to make it available on my new Fedora system. Any ideas?
[edit: Actually, it appears that the modules that I compiled successfully on my old system were older versions that used strcpy instead of strlcpy. Apparently the newer versions use strlcpy instead, so they might not compile on my old system. Also I wanted to add that at least in a couple of places, the file that refers to strlcpy is /usr/lib/perl5/5.8.8/i386-linux-thread-multi/auto/Cwd/Cwd.so]
Amy Lee
------------------------------
Date: Thu, 17 Jan 2008 23:08:54 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: undefined symbol: strlcpy
Message-Id: <pan.2008.01.17.15.08.53.68660@gmail.com>
On Thu, 17 Jan 2008 22:28:27 +0800, Amy Lee wrote:
> I am running into the error "undefined symbol: strlcpy" when trying to
> install several Perl modules (YAML, XML:Parser, XML::Simple, etc.) on a RHEL 3.
>
> From what I have read, it seems that strlcpy is a function that is included with BSD, Solaris, and OSX, but is not in the GNU C Library.
>
> However, I was able to compile these applications on my old Red Hat Linux 8.0 system without any problems, so the strlcpy function must be available in some library. I just can figure out what it is or how to make it available on my new Fedora system. Any ideas?
>
> [edit: Actually, it appears that the modules that I compiled successfully on my old system were older versions that used strcpy instead of strlcpy. Apparently the newer versions use strlcpy instead, so they might not compile on my old system. Also I wanted to add that at least in a couple of places, the file that refers to strlcpy is /usr/lib/perl5/5.8.8/i386-linux-thread-multi/auto/Cwd/Cwd.so]
>
>
> Amy Lee
I've solved this problem. Someone who have the same problem please do
follows:
Go to http://search.cpan.org/~kwilliams/PathTools-3.27/, download the
PathTools and make && make install.
Regards,
Amy Lee
------------------------------
Date: Thu, 17 Jan 2008 15:15:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help: undefined symbol: strlcpy
Message-Id: <q18465-0th.ln1@osiris.mauzo.dyndns.org>
Quoth Amy Lee <openlinuxsource@gmail.com>:
> I am running into the error "undefined symbol: strlcpy" when trying to
> install several Perl modules (YAML, XML:Parser, XML::Simple, etc.) on
> a RHEL 3.
None of the modules named use strlcpy, so the problem is elsewhere.
> From what I have read, it seems that strlcpy is a function that is
> included with BSD, Solaris, and OSX, but is not in the GNU C Library.
What is the output of
perl -V:d_strlcpy
? Do you know for certain you don't have strlcpy in your libc? (Try nm
-D /lib/libc.so.* | grep strlcpy, or sosmething equivalent.)
> However, I was able to compile these applications on my old Red Hat
> Linux 8.0 system without any problems, so the strlcpy function must be
> available in some library. I just can figure out what it is or how to
> make it available on my new Fedora system. Any ideas?
>
> [edit: Actually, it appears that the modules that I compiled
> successfully on my old system were older versions that used strcpy
> instead of strlcpy. Apparently the newer versions use strlcpy instead,
> so they might not compile on my old system. Also I wanted to add that at
> least in a couple of places, the file that refers to strlcpy is
> /usr/lib/perl5/5.8.8/i386-linux-thread-multi/auto/Cwd/Cwd.so]
Cwd.xs as distributed with 5.8.8 does not use strlcpy. Are you using a
version of perl that has been patched by RedHat? Are you perhaps using a
version of perl that was built for a different Red Hat distribution, or
a copy of Cwd.so that doesn't go with your perl? 5.10 includes an
implementation of strlcpy in the perl source, and it's possible that Red
Hat ported that change back into their 5.8.8.
Ben
------------------------------
Date: Thu, 17 Jan 2008 08:20:43 -0500
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: In perl 5.10, is $needle ~~ @haystack binary search?
Message-Id: <8uSdnRfmitGXyRLanZ2dnUVZ_siknZ2d@comcast.com>
"Abigail" <abigail@abigail.be> wrote in message news:slrnfot28d.t74.abigail@alexandra.abigail.be...
> _
> ~greg (g_m@remove-comcast.net) wrote on VCCLI September MCMXCIII in
> <URL:news:C9mdnWSIaNodwBPanZ2dnUVZ_hOdnZ2d@comcast.com>:
> !!
> !! > O (N) where N is the size of @haystack, with the assumption that
> !! > comparing two scalar can be done in constant time.
> !! >
> !! > This is optimal.
> !! >
> !! >
> !! > But does this help you? $needle ~~ @haystack might first sleep for a
> !! > week or so, and you wouldn't notice that in "big-O".
> !! >
> !! >
> !! > Abigail
> !! > --
> !!
> !! right, thanks.
> !!
> !! Best case 1, avg case N/2, worst case N.
>
> Why do you think the average case in N/2?
> Sure, if all your matches
> actually succeed, and the thing you are looking for occurs only once
> in your array, and can appear on any index with equal probability,
> the average case is N/2. But then, if all your matches always succeed
> there's no point in asking whether there's a match. The less likely
> your match succeeds, the more your average will go towards N. The more
> the thing you're looking for appears in the array (as duplicates), the
> more your average will go towards 1.
>
~~~~~
Thank you.
Why did I think that the average case was N/2?
I didn't. I wasn't thinking.
I must have mis-read it somewhere.
Possibly here - http://en.wikipedia.org/wiki/Linear_search
Anyway, thank you for forcing me to think about these things again!
I has been awhile.
I remember now that there is no substitue for clarity,
and for trying to be careful.
~~
Given completely random data,
the probability that a $needle will be found in a @haystack,
when it may not be there at all, is essentially zero,
and almost all searches will have to complete
N comparisons.
~~
Now, for the hell of it: ....
Simplifying the problem to invovle only two objects , 0 and 1,
What is the expected number of comparisons that will
have to be made before hitting the first match,
when there may be any number of matches,
or not match at all?
For example, when n=3, the sample space for this is
{000, 001, 010, 011, 100, 101, 110, 111}
and the event sets, and the random variable's values on them,
are
event "match on 1st comparison"
set = {100,101,110,111}
count = 4
prob = 4/8
value = 1
expectation = 1*(4/8)
event "match on 2nd comparison"
set = {010, 011}
count = 2
prob = 2/8
value = 2
expectation = 2 * (2/8)
event = "match on 3rd comparison"
set = {001}
count = 1
prob = 1/8
value = 3
expectation = 3*(1/8)
event = "no match after 3 comparisons"
set = {000}
count = 1
prob = 1/8
value = 3
expectation = 3*(1/8)
---------------------------------------------
Expected value = 1*(4/8) + 2*(2/8) + 3*(1/8) + 3*(1/8) = 1.75
Generally,
event "matches at kth comparison"
set = { k-1 0s, one 1, sequences of N-k 0s and 1s }
count = 2**(N-k)
prob = 2**(N-k) / 2**N = 1/2**k
value = k
expectation = k/2**k
plus
event "doesn't match after N comparions"
set = {0...0}
count = 1
prob = 1/2**N
value = N
expectation = N/2**N
So
sub Expected
{
my $N = shift;
my $e;
for(my $k=1; $k<=$N; $k++)
{
$e += $k * 2**($N-$k) / 2**$N;
}
$e += $N * (1/ (2**$N);
}
Which reduces to (2**$N - 1) / 2**($N-1)
after using a formula for the "Arithmetic power series"
which can be found, eg, here:
http://mathtable.com/errata/smtf30_errata_p2/
Which => 2
as $N => infinity.
which shouldn't come as a surprise!
Because if you toss a coin lots of times,
then you expect it to come up heads,
if not on the first toss,
then very likely on the second, ...
~~~
In any case, it's not 1, or N/2, or N.
~~~
I have been trying to figure it out when there are M objects
instead of just 2. In particular, for very large M.
(eg M=total number of integers representable on the computer).
But I am am not getting consistent results. :)
(--it has been quite awhile, and the algebra
is really hairy. But I'm trying to figure out how to use Maple again.)
The expected value will involve M.
In fact I got (a couple of times anyway)
that it will approache M, as M approaches infinity!
Which doesn't appear to make much sense. But maybe
it might. In any case I am pretty sure that the expected value
of the number of comparisons is not 1, or N/2, or N.
There are of course lots of more intelligent ways to do all this.
I just don't know what they are.
------------------------------
Date: Thu, 17 Jan 2008 09:04:50 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <x7k5m8u8jx.fsf@mail.sysarch.com>
>>>>> "IZ" == Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:
IZ> [A complimentary Cc of this posting was sent to
IZ> Uri Guttman
IZ> <uri@stemsystems.com>], who wrote in article <x7d4s1w4v1.fsf@mail.sysarch.com>:
>> do you understand me now??
IZ> a) there is no reason to yell;
there is a reason when the OP keeps banging his head on the wall and
won't listen.
IZ> b) your arguments are, IMO, wrong.
and i disagree. but you are always right so i won't argue with you. it
is a waste of time.
IZ> In a perfect world, your argument that `$@ should contain all the
IZ> information one needs' would be right. In a perfect world, presetting
IZ> these variables to FALSE would not be needed. In a perfect world,
IZ> one would not need to check $!.
and the module code can be patched in the imperfect world. or you can
write your own which i did. no problems with any error handling then.
IZ> However, as the OP had shown, the world he lives in is not perfect.
IZ> Somethign fishy is happening. So it is very logical, very polite, and
IZ> very helpful (*) that he is setting $!, $@ to FALSE, and is the value
IZ> of reporting $! to us.
nope, i did the same things and got a clean error message from $@. $! is
useless as it could be from some system call that failed but was handled
by the module. LWP does retries and such so $! may get set along the way
to a perfectly fine page fetch. if the module doesn't specify it will
use $! then looking at it is dumb.
IZ> (*) Well, not helpful enough for me to solve his problem (sorry!),
IZ> but helpful in avoiding unneeded assumptions and questions.
well, you didn't help either. so why argue about it. io::socket works
fine for everyone but the OP. i lay the blame on the obvious location.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 17 Jan 2008 06:22:08 -0800 (PST)
From: brandon <brandon.mayfield@att.net>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <b3c5f8d0-db1d-47f1-9896-e81fa9d6dd93@q39g2000hsf.googlegroups.com>
On Jan 17, 2:04=A0am, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "IZ" =3D=3D Ilya Zakharevich <nospam-ab...@ilyaz.org> writes:
>
> =A0 IZ> [A complimentary Cc of this posting was sent to
> =A0 IZ> Uri Guttman
> =A0 IZ> <u...@stemsystems.com>], who wrote in article <x7d4s1w4v1....@mail=
.sysarch.com>:
> =A0 >> do you understand me now??
>
> =A0 IZ> a) there is no reason to yell;
>
> there is a reason when the OP keeps banging his head on the wall and
> won't listen.
>
> =A0 IZ> b) your arguments are, IMO, wrong.
>
> and i disagree. but you are always right so i won't argue with you. it
> is a waste of time.
>
> =A0 IZ> In a perfect world, your argument that `$@ should contain all the
> =A0 IZ> information one needs' would be right. =A0In a perfect world, pres=
etting
> =A0 IZ> these variables to FALSE would not be needed. =A0In a perfect worl=
d,
> =A0 IZ> one would not need to check $!.
>
> and the module code can be patched in the imperfect world. or you can
> write your own which i did. no problems with any error handling then.
>
> =A0 IZ> However, as the OP had shown, the world he lives in is not perfect=
.
> =A0 IZ> Somethign fishy is happening. =A0So it is very logical, very polit=
e, and
> =A0 IZ> very helpful (*) that he is setting $!, $@ to FALSE, and is the va=
lue
> =A0 IZ> of reporting $! to us.
>
The only thing I have been able to find close to a mention of how to
determine why one's use of IO::Socket might be failing is from $@, and
that only in an example. So I am using $@ now ok? After you mentioned
this I started printing both.
> nope, i did the same things and got a clean error message from $@. $! is
> useless as it could be from some system call that failed but was handled
> by the module. LWP does retries and such so $! may get set along the way
> to a perfectly fine page fetch. if the module doesn't specify it will
> use $! then looking at it is dumb.
>
Not exactly, you did not try passing Timeout.
You helped point me to what the problem is though, it's the original
problem I am really having $! or $@ aside. This may make it more
clear :
---------- A Sun example : -----------
1) First with a port on which there is no process listening :
# uname -s
SunOS
# perl -MIO::Socket -e '$s =3D IO::Socket::INET->new(PeerAddr =3D>
"172.16.18.96", PeerPort =3D> "10" ); print "$@\n" unless $s'
IO::Socket::INET: connect: Connection refused
# perl -MIO::Socket -e '$s =3D IO::Socket::INET->new(PeerAddr =3D>
"172.16.18.96", PeerPort =3D> "10", Timeout =3D> "5"); print "$@\n"
unless $s'
IO::Socket::INET: connect: Connection refused
#
In both cases I get "connect: Connection refused", even though I am
passing a Timeout
2) Now a host that does not exist on the subnet and will timeout
# time perl -MIO::Socket -e '$s =3D IO::Socket::INET->new(PeerAddr =3D>
"172.16.18.200", PeerPort =3D> "10" ); print "$@\n" unless $s'
IO::Socket::INET: connect: Connection timed out
real 3m45.01s
user 0m0.27s
sys 0m0.04s
# set -o vi
# time perl -MIO::Socket -e '$s =3D IO::Socket::INET->new(PeerAddr =3D>
"172.16.18.200", PeerPort =3D> "10" , Timeout =3D> "5"); print "$@\n"
unless $s' <
IO::Socket::INET: connect: timeout
real 0m5.35s
user 0m0.29s
sys 0m0.05s
#
The message from $@ in the second case is set in IO::Socket and is
not the same as the first which is the text context of $!, the system
perror set in the _error() subroutine from the system call to connect.
But note that the timeout I've passed caused the call to be abandoned
after 5 seconds.
------------- An AIX example : ------------
1) Same thing as above, a port on which there is no process
listening :
# uname -srv
AIX 3 5
# perl -MIO::Socket -e '$s =3D IO::Socket::INET->new(PeerAddr =3D>
"172.16.18.96", PeerPort =3D> "10" ); print "$@\n" unless $s'
IO::Socket::INET: connect: A remote host refused an attempted connect
operation.
# perl -MIO::Socket -e '$s =3D IO::Socket::INET->new(PeerAddr =3D>
"172.16.18.96", PeerPort =3D> "10", Timeout =3D> "5"); print "$@\n"
unless $s'
IO::Socket::INET: connect: A system call received a parameter that is
not valid.
#
In the two cases above it looks to me like passing a Timeout is
causeing some heartache to the AIX build of Perl - same thing on HP.
2) And again, a host that does not exist on the subnet and will
timeout the connect
# time perl -MIO::Socket -e '$s =3D IO::Socket::INET->new(PeerAddr =3D>
"172.16.18.200", PeerPort =3D> "10" ); print "$@\n" unless $s'
IO::Socket::INET: connect: A remote host did not respond within the
timeout period.
real 1m14.80s
user 0m0.04s
sys 0m0.02s
# time perl -MIO::Socket -e '$s =3D IO::Socket::INET->new(PeerAddr =3D>
"172.16.18.200", PeerPort =3D> "10" , Timeout =3D> "5"); print "$@\n"
unless $s'
IO::Socket::INET: connect: timeout
real 0m5.00s
user 0m0.05s
sys 0m0.01s
#
So that is the behavior I think is inconsistent. Why would passing
Timout result in EINVAL on AIX and HP boxes when an error is
encountered in connect?
Thanks
------------------------------
Date: Thu, 17 Jan 2008 09:17:05 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Shrink large file according to REG_EXP
Message-Id: <13ou78io9rc51c@corp.supernews.com>
Uri Guttman wrote:
>>>>>> "nc" == nolo contendere <simon.chao@fmr.com> writes:
>
> nc> On Jan 16, 2:17 pm, Uri Guttman <u...@stemsystems.com> wrote:
> >> >>>>> "nc" == nolo contendere <simon.c...@fmr.com> writes:
> >>
> >> nc> check out /REGEX/o
> >>
> >> obsolete and probably useless.
> >>
>
> nc> really? is this since 5.10?
>
> since at least when qr// came in. also dynamic regexes (those with
> interpolation) are not recompiled unless some variable in them
> changes. this is what /o was all about in the early days of perl5. so
> it's purpose of not recompiling has been moot for eons. and qr// even
> makes it even more useless.
I won't ask you lots of questions - but do you have a link
to this info that I can read - it's of (substantial) interest
to me.
BugBear
------------------------------
Date: Thu, 17 Jan 2008 09:38:08 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Shrink large file according to REG_EXP
Message-Id: <x7abn4u70f.fsf@mail.sysarch.com>
>>>>> "b" == bugbear <bugbear@trim_papermule.co.uk_trim> writes:
b> Uri Guttman wrote:
>>>>>>> "nc" == nolo contendere <simon.chao@fmr.com> writes:
nc> On Jan 16, 2:17 pm, Uri Guttman <u...@stemsystems.com> wrote:
>> >> >>>>> "nc" == nolo contendere <simon.c...@fmr.com> writes:
>> >> >> nc> check out /REGEX/o
>> >> >> obsolete and probably useless.
>> >> nc> really? is this since 5.10?
>> since at least when qr// came in. also dynamic regexes (those with
>> interpolation) are not recompiled unless some variable in them
>> changes. this is what /o was all about in the early days of perl5. so
>> it's purpose of not recompiling has been moot for eons. and qr// even
>> makes it even more useless.
b> I won't ask you lots of questions - but do you have a link
b> to this info that I can read - it's of (substantial) interest
b> to me.
this should be in perlop under the regexp quote like ops but it doesn't
mention that /o is useless now. the faq covers it. and 5.6 is pretty old
so /o has been useless for years.
perlfaq6: What is /o really for? (code snipped)
The /o option for regular expressions (documented in perlop and
perlreref) tells Perl to compile the regular expression only once. This
is only useful when the pattern contains a variable. Perls 5.6 and later
handle this automatically if the pattern does not change.
Since the match operator m//, the substitution operator s///, and the
regular expression quoting operator qr// are double-quotish constructs,
you can interpolate variables into the pattern. See the answer to "How
can I quote a variable to use in a regex?" for more details.
Versions of Perl prior to 5.6 would recompile the regular expression for
each iteration, even if $pattern had not changed. The /o would prevent
this by telling Perl to compile the pattern the first time, then reuse
that for subsequent iterations:
In versions 5.6 and later, Perl won't recompile the regular expression
if the variable hasn't changed, so you probably don't need the /o
option. It doesn't hurt, but it doesn't help either. If you want any
version of Perl to compile the regular expression only once even if the
variable changes (thus, only using its initial value), you still need
the /o.
You can watch Perl's regular expression engine at work to verify for
yourself if Perl is recompiling a regular expression. The use re 'debug'
pragma (comes with Perl 5.005 and later) shows the details. With Perls
before 5.6, you should see re reporting that its compiling the regular
expression on each iteration. With Perl 5.6 or later, you should only
see re report that for the first iteration.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 17 Jan 2008 11:10:41 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Shrink large file according to REG_EXP
Message-Id: <13oudthllhuh311@corp.supernews.com>
Uri Guttman wrote:
>
> b> I won't ask you lots of questions - but do you have a link
> b> to this info that I can read - it's of (substantial) interest
> b> to me.
(helpful stuff snipped)
Thank you for that - most helpful.
BugBear
------------------------------
Date: Thu, 17 Jan 2008 07:20:33 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: Wait for background processes to complete
Message-Id: <367142e8-7721-46e6-8db3-329ccc219ad2@s12g2000prg.googlegroups.com>
On Jan 16, 6:52 pm, "comp.llang.perl.moderated" <c...@blv-
sam-01.ca.boeing.com> wrote:
> On Jan 16, 2:29 pm, pgodfrin <pgodf...@gmail.com> wrote:
>
>
>
> > On Jan 16, 4:17 pm, xhos...@gmail.com wrote:
>
> > > pgodfrin <pgodf...@gmail.com> wrote:
> > > > Hi Ben,
> > > > Well - it seems I have made some progress.But - I still need some
> > > > advice...
>
> > > > Here's my code:
>
> > > > #!/usr/bin/perl
> > > > use POSIX ":sys_wait_h";
> > > > $SIG{CHLD} = sub { wait }; # an 'installed' signal handler
>
> > > You probably don't need a signal handler. And if you want it,
> > > you should aware that that signal can be fired even when there is
> > > no child ready to be waited for, leading to blocking in the wait.
> > > So you would probably want to do a nonblocking waitpid instead.
>
> > > > $f=0 ;
> > > > while (</fausb/sample/*.txt>)
> > > > {
> > > > $f += 1;
> > > > if ($pid = fork)
> > > > {
> > > > print "Fork $f pid: $pid\n" ;
> > > > print "Copying $_ ($pid)\n";
> > > > # exec() NEVER returns...
> > > > exec("cp $_ $_.old") ;
> > > > } elsif (defined $pid)
> > > > {
> > > > print "Found child...($pid)\n" ;
> > > > } elsif ($! =~ /No more process/)
> > > > {
> > > > print "Fork returned no more processes\n";
> > > > } else
> > > > {
> > > > die "Fork error.\n";
> > > > } # end fork
> > > > } # end while
> > > > print "\n<<<<< End of exercise >>>>>\n";
>
> > > ## On Linux, wait returns -1 when there are no living children to wait for.
> > > 1 until -1==wait();
>
> > > > exit;
>
> > Thanks Xho - I've removed the signal handler, but it seems wait always
> > returns -1 so - the loop is a nop? Where in the code should it go?
>
> I'll pipe in here since the 'quick 'n dirty' solution
> was mangled and diss'ed.
>
> The safest action is an asynchronous wait with a
> tight loop in the handler (perldoc perlipc):
>
> use POSIX ":sys_wait_h";
> $SIG{CHLD} = \&REAPER;
>
> # now do something that forks...
> ...
>
> sub REAPER { 1 while waitpid(-1, WNOHANG)) > 0; }
>
> --
> Charles DeRykus
Hi Charles - still doesn't wait - in fact the REAPER subroutine never
even gets called - I'm beginning to get back the 'flaw' concept...
pg
------------------------------
Date: Thu, 17 Jan 2008 07:24:58 -0800 (PST)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Wait for background processes to complete
Message-Id: <36f776fa-33fa-4dea-a71b-e9dad082b666@d21g2000prf.googlegroups.com>
On Jan 17, 10:20=A0am, pgodfrin <pgodf...@gmail.com> wrote:
> On Jan 16, 6:52 pm, "comp.llang.perl.moderated" <c...@blv-
>
>
>
> sam-01.ca.boeing.com> wrote:
> > On Jan 16, 2:29 pm, pgodfrin <pgodf...@gmail.com> wrote:
>
> > > On Jan 16, 4:17 pm, xhos...@gmail.com wrote:
>
> > > > pgodfrin <pgodf...@gmail.com> wrote:
> > > > > Hi Ben,
> > > > > Well - it seems I have made some progress.But - I still need some
> > > > > advice...
>
> > > > > Here's my code:
>
> > > > > #!/usr/bin/perl
> > > > > use POSIX ":sys_wait_h";
> > > > > $SIG{CHLD} =3D sub { wait }; =A0# an 'installed' signal handler
>
> > > > You probably don't need a signal handler. =A0And if you want it,
> > > > you should aware that that signal can be fired even when there is
> > > > no child ready to be waited for, leading to blocking in the wait.
> > > > So you would probably want to do a nonblocking waitpid instead.
>
> > > > > $f=3D0 ;
> > > > > while (</fausb/sample/*.txt>)
> > > > > {
> > > > > =A0 =A0$f +=3D 1;
> > > > > =A0 =A0if ($pid =3D fork)
> > > > > =A0 =A0{
> > > > > =A0 =A0print "Fork $f pid: $pid\n" ;
> > > > > =A0 =A0print "Copying =A0$_ ($pid)\n";
> > > > > =A0 =A0# exec() NEVER returns...
> > > > > =A0 =A0exec("cp $_ $_.old") ;
> > > > > =A0 =A0} elsif (defined $pid)
> > > > > =A0 =A0{
> > > > > =A0 =A0 =A0 print "Found child...($pid)\n" ;
> > > > > =A0 =A0} elsif ($! =3D~ /No more process/)
> > > > > =A0 =A0{
> > > > > =A0 =A0 =A0 print "Fork returned no more processes\n";
> > > > > =A0 =A0} else
> > > > > =A0 =A0{
> > > > > =A0 =A0 =A0 die "Fork error.\n";
> > > > > =A0 =A0} =A0# end fork
> > > > > } =A0# end while
> > > > > print "\n<<<<< End of exercise >>>>>\n";
>
> > > > ## On Linux, wait returns -1 when there are no living children to wa=
it for.
> > > > 1 until -1=3D=3Dwait();
>
> > > > > exit;
>
> > > Thanks Xho - I've removed the signal handler, but it seems wait always=
> > > returns -1 so - the loop is a nop? Where in the code should it go?
>
> > I'll pipe in here since the 'quick 'n dirty' solution
> > was mangled and diss'ed.
>
> > The safest action is an asynchronous wait with a
> > tight loop in the handler =A0(perldoc perlipc):
>
> > =A0 =A0use POSIX ":sys_wait_h";
> > =A0 =A0$SIG{CHLD} =3D \&REAPER;
>
> > =A0 =A0# now do something that forks...
> > =A0 =A0...
>
> > =A0 =A0sub REAPER { 1 while waitpid(-1, WNOHANG)) > 0; }
>
> > --
> > Charles DeRykus
>
> Hi Charles - still doesn't wait - in fact the REAPER subroutine never
> even gets called - I'm beginning to get back the 'flaw' concept...
>
What's wrong with Xho's code earlier in the thread?
$ perl -wle 'use strict; fork or exec "sleep " . $_*3 foreach 1..3 ;
\
my $x; do {$x=3Dwait; print $x} until $x=3D=3D-1'
------------------------------
Date: Thu, 17 Jan 2008 07:36:10 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: Wait for background processes to complete
Message-Id: <25cf17a9-d1bc-48bf-a8db-630a25b910b9@n20g2000hsh.googlegroups.com>
On Jan 17, 9:24 am, nolo contendere <simon.c...@fmr.com> wrote:
> On Jan 17, 10:20 am, pgodfrin <pgodf...@gmail.com> wrote:
>
>
>
> > On Jan 16, 6:52 pm, "comp.llang.perl.moderated" <c...@blv-
>
> > sam-01.ca.boeing.com> wrote:
> > > On Jan 16, 2:29 pm, pgodfrin <pgodf...@gmail.com> wrote:
>
> > > > On Jan 16, 4:17 pm, xhos...@gmail.com wrote:
>
> > > > > pgodfrin <pgodf...@gmail.com> wrote:
> > > > > > Hi Ben,
> > > > > > Well - it seems I have made some progress.But - I still need some
> > > > > > advice...
>
> > > > > > Here's my code:
>
> > > > > > #!/usr/bin/perl
> > > > > > use POSIX ":sys_wait_h";
> > > > > > $SIG{CHLD} = sub { wait }; # an 'installed' signal handler
>
> > > > > You probably don't need a signal handler. And if you want it,
> > > > > you should aware that that signal can be fired even when there is
> > > > > no child ready to be waited for, leading to blocking in the wait.
> > > > > So you would probably want to do a nonblocking waitpid instead.
>
> > > > > > $f=0 ;
> > > > > > while (</fausb/sample/*.txt>)
> > > > > > {
> > > > > > $f += 1;
> > > > > > if ($pid = fork)
> > > > > > {
> > > > > > print "Fork $f pid: $pid\n" ;
> > > > > > print "Copying $_ ($pid)\n";
> > > > > > # exec() NEVER returns...
> > > > > > exec("cp $_ $_.old") ;
> > > > > > } elsif (defined $pid)
> > > > > > {
> > > > > > print "Found child...($pid)\n" ;
> > > > > > } elsif ($! =~ /No more process/)
> > > > > > {
> > > > > > print "Fork returned no more processes\n";
> > > > > > } else
> > > > > > {
> > > > > > die "Fork error.\n";
> > > > > > } # end fork
> > > > > > } # end while
> > > > > > print "\n<<<<< End of exercise >>>>>\n";
>
> > > > > ## On Linux, wait returns -1 when there are no living children to wait for.
> > > > > 1 until -1==wait();
>
> > > > > > exit;
>
> > > > Thanks Xho - I've removed the signal handler, but it seems wait always
> > > > returns -1 so - the loop is a nop? Where in the code should it go?
>
> > > I'll pipe in here since the 'quick 'n dirty' solution
> > > was mangled and diss'ed.
>
> > > The safest action is an asynchronous wait with a
> > > tight loop in the handler (perldoc perlipc):
>
> > > use POSIX ":sys_wait_h";
> > > $SIG{CHLD} = \&REAPER;
>
> > > # now do something that forks...
> > > ...
>
> > > sub REAPER { 1 while waitpid(-1, WNOHANG)) > 0; }
>
> > > --
> > > Charles DeRykus
>
> > Hi Charles - still doesn't wait - in fact the REAPER subroutine never
> > even gets called - I'm beginning to get back the 'flaw' concept...
>
> What's wrong with Xho's code earlier in the thread?
>
> $ perl -wle 'use strict; fork or exec "sleep " . $_*3 foreach 1..3 ;
> \
> my $x; do {$x=wait; print $x} until $x==-1'
You know what mon? Xho's program does indeed work in parallel AND
wait. Which means I really don't understand how to do this forking
( tee-hee) nonsense. I need to fix the flaw in MY architecture...
pg
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 1207
***************************************