[31681] in Perl-Users-Digest
Perl-Users Digest, Issue: 2944 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 14 18:09:26 2010
Date: Fri, 14 May 2010 15:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 14 May 2010 Volume: 11 Number: 2944
Today's topics:
Re: Do successfull poll(), sysread(), syswrite() calls <ben@morrow.me.uk>
Re: Do successfull poll(), sysread(), syswrite() calls <alexander.farber@gmail.com>
Re: Do successfull poll(), sysread(), syswrite() calls <uri@StemSystems.com>
Re: Do successfull poll(), sysread(), syswrite() calls <ben@morrow.me.uk>
Re: MinGW and Perl 5.12 - Windows 32 bits ActiveState <dilbert1999@gmail.com>
MinGW and Perl 5.12 - Windows 64 bits ActiveState <dilbert1999@gmail.com>
perl format statement, how do I begin a line with a has <joinerda@gmail.com>
Re: perl format statement, how do I begin a line with a <ralph@happydays.com>
Re: perl format statement, how do I begin a line with a <rus20376@copper.net>
Re: perl format statement, how do I begin a line with a <rus20376@copper.net>
Re: perl format statement, how do I begin a line with a <joinerda@gmail.com>
Re: perl format statement, how do I begin a line with a <joinerda@gmail.com>
Re: perl format statement, how do I begin a line with a <john@castleamber.com>
Re: perl format statement, how do I begin a line with a <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 14 May 2010 14:08:00 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Do successfull poll(), sysread(), syswrite() calls clear %!
Message-Id: <giuvb7-q8h1.ln1@osiris.mauzo.dyndns.org>
Quoth "A. Farber" <alexander.farber@gmail.com>:
>
> However once in a week the perl process would
> "spin up" up to 98% CPU and would stop responding.
>
> It is difficult to find the reason for this and
> I can't reproduce it while testing myself.
>
> I've made the listening TCP socket
> non-blocking to prevent DOS attacks and
> the main loop in my server looks like this:
>
<snip>
>
> sub write {
> my $child = shift;
> my $fh = $child->{FH};
> my $len = bytes::length $child->{RESPONSE};
Don't use bytes::length. If $child->{RESPONSE} might contain Unicode
characters, you need to pass it through Encode::encode before
transmitting it.
> my $nbytes;
>
> $nbytes = $fh->syswrite($child->{RESPONSE}, $len);
>
> unless (defined $nbytes) {
> # would block - retry later
> return 1 if $!{EAGAIN} || $!{EWOULDBLOCK};
>
> # interrupted by signal - retry later
> return 1 if $!{EINTR};
> # connection interrupted
> return 0;
> }
>
> # connection closed
> return 0 if 0 == $nbytes;
>
> substr $child->{RESPONSE}, 0, $nbytes, '';
> return 1;
> }
>
> I wonder, if this retrying (as shown above)
> is the real reason for the "spin-ups" somehow?
> Should I maybe clear $!{EINTR} etc.
> manually whenever $nbytes is undefined?
No, $!{EINTR} is exactly equivalent to ($! == EINTR).
Ben
------------------------------
Date: Fri, 14 May 2010 07:29:45 -0700 (PDT)
From: "A. Farber" <alexander.farber@gmail.com>
Subject: Re: Do successfull poll(), sysread(), syswrite() calls clear %!
Message-Id: <b7255265-8dc4-4e60-935a-1c6855ca97bb@r34g2000yqj.googlegroups.com>
Hello Ben,
On May 14, 3:08 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth "A. Farber" <alexander.far...@gmail.com>:
> > my $len = bytes::length $child->{RESPONSE};
>
> Don't use bytes::length. If $child->{RESPONSE} might contain Unicode
> characters, you need to pass it through Encode::encode before
> transmitting it.
>
> > $nbytes = $fh->syswrite($child->{RESPONSE}, $len);
yes it contains Unicode (cyrillic + latin chars in UTF8).
If I pass it through encode and do not use bytes::length
as you suggest, how will I get the number of bytes for syswrite?
> > unless (defined $nbytes) {
> > # would block - retry later
> > return 1 if $!{EAGAIN} || $!{EWOULDBLOCK};
>
> > # interrupted by signal - retry later
> > return 1 if $!{EINTR};
> > # connection interrupted
> > return 0;
> > }
> No, $!{EINTR} is exactly equivalent to ($! == EINTR).
Ok, but for example: sysreading from one socket fails
with $!{EINTR} (because I use USR1 and -USR2
in my script to dump data structures). I do not close
that socket and plan to sysread from it again in next loop.
Then sysreading from another socket fails, because
TCP-connection has been interrupted.
Will $!{EINTR} be cleared or still set (from the prev. socket)?
Regards
Alex
------------------------------
Date: Fri, 14 May 2010 12:15:49 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Do successfull poll(), sysread(), syswrite() calls clear %!
Message-Id: <87vdaqihmy.fsf@quad.sysarch.com>
>>>>> "AF" == A Farber <alexander.farber@gmail.com> writes:
AF> Hello Ben,
AF> On May 14, 3:08 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>> Quoth "A. Farber" <alexander.far...@gmail.com>:
>> > my $len = bytes::length $child->{RESPONSE};
>>
>> Don't use bytes::length. If $child->{RESPONSE} might contain Unicode
>> characters, you need to pass it through Encode::encode before
>> transmitting it.
>>
>> > $nbytes = $fh->syswrite($child->{RESPONSE}, $len);
AF> yes it contains Unicode (cyrillic + latin chars in UTF8).
AF> If I pass it through encode and do not use bytes::length
AF> as you suggest, how will I get the number of bytes for syswrite?
syswrite can skip the len argument and just send what is in the
buffer. i haven't tried this with utf but it should work just
fine. internally it will see how many bytes are in the buffer and send
that.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 14 May 2010 17:43:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Do successfull poll(), sysread(), syswrite() calls clear %!
Message-Id: <o5b0c7-q9i1.ln1@osiris.mauzo.dyndns.org>
Quoth "A. Farber" <alexander.farber@gmail.com>:
> Hello Ben,
>
> On May 14, 3:08 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth "A. Farber" <alexander.far...@gmail.com>:
> > > my $len = bytes::length $child->{RESPONSE};
> >
> > Don't use bytes::length. If $child->{RESPONSE} might contain Unicode
> > characters, you need to pass it through Encode::encode before
> > transmitting it.
> >
> > > $nbytes = $fh->syswrite($child->{RESPONSE}, $len);
>
> yes it contains Unicode (cyrillic + latin chars in UTF8).
> If I pass it through encode and do not use bytes::length
> as you suggest, how will I get the number of bytes for syswrite?
If it's a true Unicode string, then you need
my $bytes = Encode::encode "UTF-8" => $child->{RESPONSE};
my $len = length $bytes;
$nbytes = $fh->syswrite($bytes, $len);
You will also need to fix the buffer-trimming logic below, to work on
the byte string instead of the character string. You may need a new
entry in $child, $child->{RESPONSE_BYTES}, to hold the section of the
string that's been encoded but hasn't been transmitted yet.
If it's already encoded in UTF8 (so that, as far as Perl is concerned,
none of the characters have ord > 255) then just replace bytes::length
with length.
> > > unless (defined $nbytes) {
> > > # would block - retry later
> > > return 1 if $!{EAGAIN} || $!{EWOULDBLOCK};
> >
> > > # interrupted by signal - retry later
> > > return 1 if $!{EINTR};
> > > # connection interrupted
> > > return 0;
> > > }
>
> > No, $!{EINTR} is exactly equivalent to ($! == EINTR).
>
> Ok, but for example: sysreading from one socket fails
> with $!{EINTR} (because I use USR1 and -USR2
> in my script to dump data structures). I do not close
> that socket and plan to sysread from it again in next loop.
>
> Then sysreading from another socket fails, because
> TCP-connection has been interrupted.
>
> Will $!{EINTR} be cleared or still set (from the prev. socket)?
$!{EINTR} will still be true if and only if $! is still equal to EINTR.
%! is readonly, and you will get an error if you try to set or clear any
of the entries yourself.
Ben
------------------------------
Date: Fri, 14 May 2010 06:25:20 -0700 (PDT)
From: Dilbert <dilbert1999@gmail.com>
Subject: Re: MinGW and Perl 5.12 - Windows 32 bits ActiveState
Message-Id: <602225e9-de93-4472-97c0-a6c72a1c9e76@j35g2000yqm.googlegroups.com>
On 14 mai, 14:01, Bart Lateur <bart.lat...@telenet.be> wrote:
> Dilbert wrote:
> >I know, I can get MinGW64 athttp://mingw-w64.sourceforge.net/or I
> >can grab the freely available "Microsoft Platform SDK for Windows
> >Server 2003 R2", but I like the "no brain, no pain" philosophy of a
> >"ppm install MinGW". So I tried "ppm install MinGW" on Activestate
> >Perl 5.12 - Windows 64 bits, but there is still no MinGW Package
> >available for 64 bits on the Activestate repo.
>
> >Then I tried "ppm install MinGW" on Perl 5.12 - Windows 32 bits, and
> >guess what -- it worked.
>
> >Hurray, the MinGW Package for Perl 5.12 (Windows 32 bits) is now
> >available from the Activestate repo. -- *** A big thank you to all
> >those who made this possible !!! *** -- I don't take MinGW for granted
> >(next step for me is to test CPANPLUS with Activestate Perl 5.12 to
> >install xs based modules under Windows)
>
> If your Perl is 32 bits, then your modules should be built for 32 bits,
> too.
I have got two computers:
- one computer with Windows Vista 64 bits and Activestate Perl 5.12 -
64 bits
- another computer with Windows XP 32 bits and Activestate Perl 5.12
- 32 bits
As already described in the other posts in this thread, I am happy
with "ppm install MinGW" on my 32 bits computer.
However, on my other 64 bits computer, (although I can perfectly
understand that "ppm install MinGW" does not work on a 64 bit Windows
system) I still need to have a C-compiler to build XS-modules from
CPAN.
First I tried to get MinGW64 at http://mingw-w64.sourceforge.net/, but
I could not find any package/zip file that contained the required pre-
compiled *.exe files for Windows 64 bits.
Then I tried the freely available "Microsoft Platform SDK for Windows
Server 2003 R2", but honestly, this is a nightmare: first of all, the
download+install of VC++/Platform SDK is more than 200 megs, then the
linker complains with a message: fatal error LNK1112: module machine
type 'X86' conflicts with target machine type 'x64'.
I was looking at the article
http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/
to fix my problems, but on my system I can't even find the slightest
trace of any of the x64/amdx64 directories/dlls mentioned in the
article.
I can understand that a big company like Activestate can afford to use
a MS Visual C++ compiler, but I am simply not clever enough to use the
freely available compiler from Microsoft.
My only hope is that the good people who gave us "ppm install MinGW"
on 32 bits, will repeat their efforts and release the same for 64
bits.
------------------------------
Date: Fri, 14 May 2010 10:41:52 -0700 (PDT)
From: Dilbert <dilbert1999@gmail.com>
Subject: MinGW and Perl 5.12 - Windows 64 bits ActiveState
Message-Id: <6e8d0575-e692-4cc1-b15e-efb78e06a430@i10g2000yqh.googlegroups.com>
[ subject changed to: "MinGW and Perl 5.12 - Windows 64 bits
ActiveState" ]
On 14 mai, 15:25, Dilbert <dilbert1...@gmail.com> wrote:
> On 14 mai, 14:01, Bart Lateur <bart.lat...@telenet.be> wrote:
> > Dilbert wrote:
> > >I know, I can get MinGW64 athttp://mingw-w64.sourceforge.net/orI
> > >can grab the freely available "Microsoft Platform SDK for Windows
> > >Server 2003 R2", but I like the "no brain, no pain" philosophy of a
> > >"ppm install MinGW". So I tried "ppm install MinGW" on Activestate
> > >Perl 5.12 - Windows 64 bits, but there is still no MinGW Package
> > >available for 64 bits on the Activestate repo.
>
> > If your Perl is 32 bits, then your modules should be built for 32 bits,
> > too.
>
> I have got two computers:
>
> =A0- one computer with Windows Vista 64 bits and Activestate Perl 5.12 -
> 64 bits
> =A0- another computer with Windows XP 32 bits and Activestate Perl 5.12
> - 32 bits
>
> As already described in the other posts in this thread, I am happy
> with "ppm install MinGW" on my 32 bits computer.
>
> However, on my other 64 bits computer, (although I can perfectly
> understand that "ppm install MinGW" does not work on a 64 bit Windows
> system) I still need to have a C-compiler to build XS-modules from
> CPAN.
>
> First I tried to get MinGW64 athttp://mingw-w64.sourceforge.net/, but
> I could not find any package/zip file that contained the required pre-
> compiled *.exe files for Windows 64 bits.
>
> Then I tried the freely available "Microsoft Platform SDK for Windows
> Server 2003 R2", but honestly, this is a nightmare: first of all, the
> download+install of VC++/Platform SDK is more than 200 megs, then the
> linker complains with a message: fatal error LNK1112: module machine
> type 'X86' conflicts with target machine type 'x64'.
>
> I was looking at the articlehttp://jenshuebel.wordpress.com/2009/02/12/vi=
sual-c-2008-express-edit...
> to fix my problems, but on my system I can't even find the slightest
> trace of any of the x64/amdx64 directories/dlls mentioned in the
> article.
>
> I can understand that a big company like Activestate can afford to use
> a MS Visual C++ compiler, but I am simply not clever enough to use the
> freely available compiler from Microsoft.
It looks very much as if there simply is no 64 bits in the free
available compiler from Microsoft, only 32 bits :(
I am just thinking: is there not a manipulation somewhere in "use
Config" that tricks Makefile.PL and Build.PL into thinking it was on a
32 bit platform ? -- Maybe then the compile and link will succeed as a
32 bit application, and the 32 bit program should work fine, even with
a 64 bit Perl ? -- or is my thinking wrong ?
> My only hope is that the good people who gave us "ppm install MinGW"
> on 32 bits, will repeat their efforts and release the same for 64
> bits.
Whatever the outcome of my battle with MS VC++ will be, I will be
relieved when "ppm install MinGW" works on 64 bit Windows.
------------------------------
Date: Fri, 14 May 2010 11:35:03 -0700 (PDT)
From: joinerda <joinerda@gmail.com>
Subject: perl format statement, how do I begin a line with a hash mark?
Message-Id: <60c2e680-784f-4468-bfbe-7738507c0d44@24g2000yqy.googlegroups.com>
I would like to use a perl format statement to autogenerate qsub files
for a PBS scheduler. The files I need to generate are essentially
shell scripts with comments beginning with a hash mark to denote them
as pragma for the scheduler.
If I create a format statement that looks like
format QSUBFILE =
#PBS -N @<<<<<<<<<
$queue
.
the line beginning with a hash mark is read as a comment by PERL,
instead of a line that needs to be printed that starts with a hash
mark.
How can I using a PERL format statement generate a number of files all
of which has as their first few lines variations of
#PBS -N dustfit
#PBS -q default
#PBS -l nodes=1:ppn=8
#PBS -l cput=6000:00:00
------------------------------
Date: Fri, 14 May 2010 14:55:49 -0400
From: Ralph Malph <ralph@happydays.com>
Subject: Re: perl format statement, how do I begin a line with a hash mark?
Message-Id: <15a01$4bed9cb6$40779ac3$22533@news.eurofeeds.com>
On 5/14/2010 2:35 PM, joinerda wrote:
> I would like to use a perl format statement to autogenerate qsub files
> for a PBS scheduler. The files I need to generate are essentially
> shell scripts with comments beginning with a hash mark to denote them
> as pragma for the scheduler.
>
> If I create a format statement that looks like
>
> format QSUBFILE =
> #PBS -N @<<<<<<<<<
> $queue
> .
The easiest option is to just add a leading space before the #
format QSUBFILE =
#PBS -N @<<<<<<<<<
$queue
.
will end up printing exactly what you want but the first column will be
empty.
------------------------------
Date: Fri, 14 May 2010 15:02:40 -0400
From: arus <rus20376@copper.net>
Subject: Re: perl format statement, how do I begin a line with a hash mark?
Message-Id: <e13cc$4bed9e50$40779ac3$19424@news.eurofeeds.com>
On 5/14/2010 2:35 PM, joinerda wrote:
> I would like to use a perl format statement to autogenerate qsub files
> for a PBS scheduler. The files I need to generate are essentially
> shell scripts with comments beginning with a hash mark to denote them
> as pragma for the scheduler.
>
> If I create a format statement that looks like
>
> format QSUBFILE =
> #PBS -N @<<<<<<<<<
> $queue
> .
Put the hashmark in a variable
Eg)
my $hm="#";
format QSUBFILE =
@#PBS -N @<<<<<<<<<
$hm,$queue
.
Best Regards,
Adam
------------------------------
Date: Fri, 14 May 2010 15:04:11 -0400
From: arus <rus20376@copper.net>
Subject: Re: perl format statement, how do I begin a line with a hash mark?
Message-Id: <787e0$4bed9eab$40779ac3$19424@news.eurofeeds.com>
On 5/14/2010 3:02 PM, arus wrote:
> On 5/14/2010 2:35 PM, joinerda wrote:
>> I would like to use a perl format statement to autogenerate qsub files
>> for a PBS scheduler. The files I need to generate are essentially
>> shell scripts with comments beginning with a hash mark to denote them
>> as pragma for the scheduler.
>>
>> If I create a format statement that looks like
>>
>> format QSUBFILE =
>> #PBS -N @<<<<<<<<<
>> $queue
>> .
> Put the hashmark in a variable
> Eg)
> my $hm="#";
> format QSUBFILE =
> @#PBS -N @<<<<<<<<<
> $hm,$queue
> .
I forgot to delete your original #.
Please correct that to read
Eg)
my $hm="#";
format QSUBFILE =
@PBS -N @<<<<<<<<<
$hm,$queue
.
------------------------------
Date: Fri, 14 May 2010 12:30:33 -0700 (PDT)
From: joinerda <joinerda@gmail.com>
Subject: Re: perl format statement, how do I begin a line with a hash mark?
Message-Id: <ea86acb5-40a1-4f00-99e9-98548e81f469@q8g2000vbm.googlegroups.com>
I thought about that, but the file has a space in the line that breaks
the way the file is parsed by the scheduler. I need the first
character of the line to be a hash. I can do this with print or printf
statements easily enough, but I am trying to come up with a solution
where the format statement looks as much as possible like the files my
end-users (who tend to ask things like "what is backslash n again?")
are used to dealing with so that this is easier to do in the future.
On May 14, 2:55=A0pm, Ralph Malph <ra...@happydays.com> wrote:
> On 5/14/2010 2:35 PM, joinerda wrote:
>
> > I would like to use a perl format statement to autogenerate qsub files
> > for a PBS scheduler. The files I need to generate are essentially
> > shell scripts with comments beginning with a hash mark to denote them
> > as pragma for the scheduler.
>
> > If I create a format statement that looks like
>
> > format QSUBFILE =3D
> > #PBS -N @<<<<<<<<<
> > =A0 =A0 =A0 =A0 =A0$queue
> > .
>
> The easiest option is to just add a leading space before the #
> format QSUBFILE =3D
> =A0 #PBS -N @<<<<<<<<<
> =A0 =A0 =A0 =A0 =A0 $queue
> =A0 .
>
> will end up printing exactly what you want but the first column will be
> empty.
------------------------------
Date: Fri, 14 May 2010 12:34:09 -0700 (PDT)
From: joinerda <joinerda@gmail.com>
Subject: Re: perl format statement, how do I begin a line with a hash mark?
Message-Id: <76313140-7145-4cd6-85c2-11178f36b35a@i31g2000vbt.googlegroups.com>
That's a possibility. I'm using print statements right now, but I'm
trying to come up with a solution for my end-users that looks as much
as possible like the input files they are used to. I wonder what will
confuse them more, an extra variable in the format statement, or lots
of print and/or printf statements.
Thanks!
On May 14, 3:04=A0pm, arus <rus20...@copper.net> wrote:
> On 5/14/2010 3:02 PM, arus wrote:
>
> > On 5/14/2010 2:35 PM, joinerda wrote:
> >> I would like to use a perl format statement to autogenerate qsub files
> >> for a PBS scheduler. The files I need to generate are essentially
> >> shell scripts with comments beginning with a hash mark to denote them
> >> as pragma for the scheduler.
>
> >> If I create a format statement that looks like
>
> >> format QSUBFILE =3D
> >> #PBS -N @<<<<<<<<<
> >> $queue
> >> .
> > Put the hashmark in a variable
> > Eg)
> > my $hm=3D"#";
> > format QSUBFILE =3D
> > @#PBS -N @<<<<<<<<<
> > $hm,$queue
> > .
>
> I forgot to delete your original #.
> Please correct that to read
> Eg)
> my $hm=3D"#";
> format QSUBFILE =3D
> @PBS -N @<<<<<<<<<
> $hm,$queue
> .
------------------------------
Date: Fri, 14 May 2010 15:37:27 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: perl format statement, how do I begin a line with a hash mark?
Message-Id: <87zl02md88.fsf@castleamber.com>
joinerda <joinerda@gmail.com> writes:
posting top not for you thank.
> That's a possibility. I'm using print statements right now, but I'm
> trying to come up with a solution for my end-users that looks as much
> as possible like the input files they are used to. I wonder what will
> confuse them more, an extra variable in the format statement, or lots
> of print and/or printf statements.
Use a templating module, see CPAN. Or format your scalars with sprintf
and use a <<HERE document.
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
Date: Fri, 14 May 2010 16:24:57 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: perl format statement, how do I begin a line with a hash mark?
Message-Id: <slrnhurfjn.ak4.tadmc@tadbox.sbcglobal.net>
John Bokma <john@castleamber.com> wrote:
> posting top not for you thank.
one good!
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2944
***************************************