[31402] in Perl-Users-Digest
Perl-Users Digest, Issue: 2654 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 28 14:09:48 2009
Date: Wed, 28 Oct 2009 11:09:13 -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 Wed, 28 Oct 2009 Volume: 11 Number: 2654
Today's topics:
bignum::bdiv() not working correctly on integers <jl_post@hotmail.com>
Re: File locking using threads <ben@morrow.me.uk>
Re: How to prevent hanging when writing lots of text to <jl_post@hotmail.com>
Re: How to prevent hanging when writing lots of text to <jl_post@hotmail.com>
Re: How to prevent hanging when writing lots of text to <ben@morrow.me.uk>
Re: How to prevent hanging when writing lots of text to <ben@morrow.me.uk>
Re: How to prevent hanging when writing lots of text to <jl_post@hotmail.com>
Re: How to prevent hanging when writing lots of text to <jl_post@hotmail.com>
Math::GMP and Pari Installed, But BigInt Can't Find The <hsomob1999@yahoo.com>
Re: Math::GMP and Pari Installed, But BigInt Can't Find <ben@morrow.me.uk>
Re: Math::GMP and Pari Installed, But BigInt Can't Find <hsomob1999@yahoo.com>
Net::SFTP Fails, sftp OK <hsomob1999@yahoo.com>
Re: Net::SFTP Fails, sftp OK <hsomob1999@yahoo.com>
Re: Perl bioinformatics <rvtol+usenet@xs4all.nl>
Perl IDE ScriptDev V2.3 released <scriptdevsupport@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Oct 2009 09:57:06 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: bignum::bdiv() not working correctly on integers
Message-Id: <745e8da3-1703-4707-b33a-083f9303d1c2@e4g2000prn.googlegroups.com>
Hi,
I've recently discovered that if I create a "bignum" object in Perl
and call the ->bdiv() method, sometimes the object will get modified
and sometimes it won't. Here's a sample program that illustrates what
I'm talking about:
#!/usr/bin/perl
use strict;
use warnings;
use bignum;
my $n1 = 6.6;
print "\$n1 before \$n1->bdiv(2): $n1\n"; # prints 6.6
$n1->bdiv(2);
print "\$n1 after \$n1->bdiv(2): $n1\n"; # prints 3.3
print "\n";
my $n2 = 6;
print "\$n2 before \$n2->bdiv(2): $n2\n"; # prints 6
$n2->bdiv(2);
print "\$n2 after \$n2->bdiv(2): $n2\n"; # prints 6 (error?)
__END__
I've tested this script on both Windows and Unix, and the output is
the same. I changed "use bignum" to "use bigint" and I saw the
expected 6, 3, and 6, 3 as output. (The floating-point numbers were
truncated, but that's no surprise since we're working with integers.)
I also changed "bdiv" to "bmul" (using the "bignum" module) and I
saw the expected 6.6, 13.2, and 6, 12 as output, so apparently
bignum::dmul() works consistently.
I've noticed that bignum::bdiv() seems to modify the calling object
if the value is a floating-point number (that is, cannot be
represented as an integer). But if the calling object is an integer
(even one with a decimal point like 6.0), then bignum::bdiv() does not
modify it.
I noticed that if I print out ref($n1) and ref($n2), I see that $n1
is a Math::BigFloat and that $n2 is a Math::BigInt. So I might think
that the problem lies in the Math::BigInt module. However, when I
change "use bignum" to "use bigint", they both become Math::BigInt
objects, but now the bdiv() method is modifying the calling object (as
I think it should).
So it doesn't look like the problem is with Math::BigInt, but
rather with the "bignum" module.
Is this incosistent behavior of the "bignum" module a bug, or am I
missing something? I haven't seen much code that uses the "bigint"
and "bignum" modules, so as far as I know they're deprecated, but I
haven't read anything to that effect.
-- Jean-Luc
------------------------------
Date: Tue, 27 Oct 2009 13:29:22 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: File locking using threads
Message-Id: <i69jr6-86g2.ln1@osiris.mauzo.dyndns.org>
Quoth Prince Al <timothy.hill@gmail.com>:
>
> First, many thanks for the taking the time to help me out - very much
> appreciated :-) Answers to the various queries posted above are...
>
> OS is HP-UX B.11.11 U
Right. http://docs.hp.com/en/B3921-60631/flock.2.html makes it very
clear that HP-UX emulates flock locks using POSIX locks, so the
behaviour you originally posted about is expected.
Ben
------------------------------
Date: Tue, 27 Oct 2009 08:19:31 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: How to prevent hanging when writing lots of text to a pipe?
Message-Id: <0020c445-66f0-44dd-b7b2-b1129dba8eea@x6g2000prc.googlegroups.com>
On Oct 23, 10:27=A0am, ilovelinux <c7eqjy...@sneakemail.com> wrote:
>
> Pipes have a limited capacity. See http://linux.die.net/man/7/pipe.
> Posix prescribes a minimum capacity of 512, which is exactly
> implemented on your windows machine:
> $ perl -we 'print "$_\n" for 1..155'| wc -c
> 512
Thanks for the info. Now that I know this, I have a quick
question:
Say I'm writing to a pipe in a child thread, while the parent is
reading from the pipe. If the child writes an extremely long line of
text to the pipe (like 50,000 characters ending in a newline), will
that cause deadlock?
I ask this because the parent generally reads one (newline-
terminated) line at a time when using Perl's diamond operator. If
Perl's pipe capacity is 512 (or 4096), then the child will have
written that capacity well before the parent can read that line (and
therefore before the pipe is cleared).
The good news is that I'm testing this by piping a lot of text with
the line:
print $writeHandle $_ x 10000, "\n" foreach 1 .. $number;
and there doesn't seem to be a problem, despite the fact that the
newline comes well after the 512/4096 pipe buffer limit you informed
me of.
The only explanation I can think of is that Perl itself has to read
the pipe (and therefore clear its buffer) in order to see if a newline
character is in the "pipeline". Maybe in doing so Perl transfers the
text from the pipe's buffer to a Perl internal buffer, effectively
clearing the pipe and preventing deadlock from happening.
But that's my guess. I'd like to know what you (or anybody else)
have to say about it. (Hopefully I made myself clear enough to
understand.)
Thanks for any advice.
-- Jean-Luc
------------------------------
Date: Tue, 27 Oct 2009 08:24:04 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: How to prevent hanging when writing lots of text to a pipe?
Message-Id: <ef933b1b-8b2e-4006-b0c7-4a41914f4194@y28g2000prd.googlegroups.com>
> jl_p...@hotmail.com wrote:
> >
> > =A0 =A0I could have used this instead:
> >
> > =A0 =A0 =A0 split m/(?<=3D\n)(?!\z)/, $output;
On Oct 26, 10:29 pm, "John W. Krahn" <some...@example.com> wrote:
> Or this:
>
> =A0 =A0 =A0 =A0 =A0$output =3D~ /.*\n/g;
Hey, that's clever! I like it!
However, there's a tiny difference: Your way will discard the last
line if $output does not end in a newline character, whereas the first
way will keep the line.
(Of course, this won't be an issue if $output is guaranteed to end
in a newline.)
-- Jean-Luc
------------------------------
Date: Tue, 27 Oct 2009 16:27:40 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to prevent hanging when writing lots of text to a pipe?
Message-Id: <skjjr6-jk8.ln1@osiris.mauzo.dyndns.org>
Quoth "jl_post@hotmail.com" <jl_post@hotmail.com>:
> On Oct 23, 10:27 am, ilovelinux <c7eqjy...@sneakemail.com> wrote:
> >
> > Pipes have a limited capacity. See http://linux.die.net/man/7/pipe.
> > Posix prescribes a minimum capacity of 512, which is exactly
> > implemented on your windows machine:
> > $ perl -we 'print "$_\n" for 1..155'| wc -c
> > 512
>
>
> Thanks for the info. Now that I know this, I have a quick
> question:
>
> Say I'm writing to a pipe in a child thread, while the parent is
> reading from the pipe. If the child writes an extremely long line of
> text to the pipe (like 50,000 characters ending in a newline), will
> that cause deadlock?
If you have only one pipe, one thread that is only writing and one
thread that is only reading, you cannot get deadlock. You may end up in
a situation where the child is blocked in write(2) waiting for the
parent to read data, but that will resolve at some point since the
parent isn't blocking on the child.
> I ask this because the parent generally reads one (newline-
> terminated) line at a time when using Perl's diamond operator. If
> Perl's pipe capacity is 512 (or 4096), then the child will have
> written that capacity well before the parent can read that line (and
> therefore before the pipe is cleared).
>
> The good news is that I'm testing this by piping a lot of text with
> the line:
>
> print $writeHandle $_ x 10000, "\n" foreach 1 .. $number;
>
> and there doesn't seem to be a problem, despite the fact that the
> newline comes well after the 512/4096 pipe buffer limit you informed
> me of.
>
> The only explanation I can think of is that Perl itself has to read
> the pipe (and therefore clear its buffer) in order to see if a newline
> character is in the "pipeline". Maybe in doing so Perl transfers the
> text from the pipe's buffer to a Perl internal buffer, effectively
> clearing the pipe and preventing deadlock from happening.
That is correct. When you read from a filehandle using the <> operator,
perl actually reads large chunks and buffers the result, then goes
hunting through the buffer for a newline. If it doesn't find one, it
will keep reading chunks (and extending the buffer) until it does, so
reading really long lines needs lots of buffer space in the perl
process, not lots of room in the pipe.
Ben
------------------------------
Date: Tue, 27 Oct 2009 16:30:18 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to prevent hanging when writing lots of text to a pipe?
Message-Id: <qpjjr6-jk8.ln1@osiris.mauzo.dyndns.org>
Quoth "jl_post@hotmail.com" <jl_post@hotmail.com>:
>
> On Oct 26, 10:29 pm, "John W. Krahn" <some...@example.com> wrote:
> > Or this:
> >
> > $output =~ /.*\n/g;
>
>
> Hey, that's clever! I like it!
>
> However, there's a tiny difference: Your way will discard the last
> line if $output does not end in a newline character, whereas the first
> way will keep the line.
split /^/m, $output;
Ben
------------------------------
Date: Tue, 27 Oct 2009 10:13:06 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: How to prevent hanging when writing lots of text to a pipe?
Message-Id: <ba3a5b3e-4331-4f90-b1a0-38967b114fdc@r24g2000prf.googlegroups.com>
On Oct 27, 10:30=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
>
> =A0 =A0 split /^/m, $output;
Excellent way to split out lines! Thanks!
-- Jean-Luc
------------------------------
Date: Wed, 28 Oct 2009 09:58:17 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: How to prevent hanging when writing lots of text to a pipe?
Message-Id: <9fd125c3-920c-4e6b-843b-76b6c602279a@y10g2000prg.googlegroups.com>
On Oct 27, 10:27=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
>
> When you read from a filehandle using the <> operator,
> perl actually reads large chunks and buffers the result, then goes
> hunting through the buffer for a newline. If it doesn't find one, it
> will keep reading chunks (and extending the buffer) until it does, so
> reading really long lines needs lots of buffer space in the perl
> process, not lots of room in the pipe.
That makes sense. Thank you.
-- Jean-Luc
------------------------------
Date: Tue, 27 Oct 2009 13:25:44 -0700 (PDT)
From: MaggotChild <hsomob1999@yahoo.com>
Subject: Math::GMP and Pari Installed, But BigInt Can't Find Them
Message-Id: <bd3f17d8-eda9-43ba-baed-405c6c9a2c6c@w37g2000prg.googlegroups.com>
> perl -MMath::Pari -e'$a=PARI 2;print $a**10000'
#Big number...
> perl -MMath::GMP -e'print Math::GMP->new(2) ** 1000'
#Same Big Number...
> perl -e'use Math::BigInt lib => "GMP,Pari";'
Math::BigInt: couldn't load specified math lib(s), fallback to
Math::BigInt::Calc at -e line 1
What gives?
As an aside, is it possible to import GMP or Pari from the command
line? -M doesn't play nice with a string of import args:
> perl -MMath::BigInt='lib,Pari' -e'1'
#OK, can't load module error
But:
> perl -MMath::BigInt='lib,"GMP,Pari"' -e'1'
"Pari"" is not exported by the Math::BigInt module
Can't continue after import errors at -e line 0
BEGIN failed--compilation aborted.
------------------------------
Date: Tue, 27 Oct 2009 21:20:50 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Math::GMP and Pari Installed, But BigInt Can't Find Them
Message-Id: <iq4kr6-ama.ln1@osiris.mauzo.dyndns.org>
Quoth MaggotChild <hsomob1999@yahoo.com>:
> > perl -MMath::Pari -e'$a=PARI 2;print $a**10000'
> #Big number...
>
> > perl -MMath::GMP -e'print Math::GMP->new(2) ** 1000'
> #Same Big Number...
>
> > perl -e'use Math::BigInt lib => "GMP,Pari";'
> Math::BigInt: couldn't load specified math lib(s), fallback to
> Math::BigInt::Calc at -e line 1
>
> What gives?
You also need to install Math::BigInt::GMP and Math::BigInt::Pari. (I
believe the former doesn't actually use the Math::GMP bindings at all,
and instead links with the C library directly.)
> As an aside, is it possible to import GMP or Pari from the command
> line? -M doesn't play nice with a string of import args:
>
> > perl -MMath::BigInt='lib,Pari' -e'1'
> #OK, can't load module error
>
> But:
> > perl -MMath::BigInt='lib,"GMP,Pari"' -e'1'
> "Pari"" is not exported by the Math::BigInt module
> Can't continue after import errors at -e line 0
> BEGIN failed--compilation aborted.
This expands to
use Math::BigInt split(/,/,q^@lib,"GMP,Pari"^@);
where '^@' represents a literal zero byte (I bet you didn't know Perl
allowed that as a quote delimiter :)). This is equivalent to
use Math::BigInt 'lib', '"GMP', 'PARI"';
which is not what you meant at all. You can however write
perl -M'Math::BigInt lib => "GMP,Pari"' -e1
and it will work just fine.
Ben
------------------------------
Date: Wed, 28 Oct 2009 09:30:05 -0700 (PDT)
From: MaggotChild <hsomob1999@yahoo.com>
Subject: Re: Math::GMP and Pari Installed, But BigInt Can't Find Them
Message-Id: <8236ff10-dec4-4a46-b7b3-494ae4522296@u36g2000prn.googlegroups.com>
On Oct 27, 1:20=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth MaggotChild <hsomob1...@yahoo.com>:
>
> > > perl -MMath::Pari -e'$a=3DPARI 2;print $a**10000'
> > #Big number...
>
> > > perl -MMath::GMP -e'print Math::GMP->new(2) ** 1000'
> > #Same Big Number...
>
> > > perl -e'use Math::BigInt lib =3D> "GMP,Pari";'
> > Math::BigInt: couldn't load specified math lib(s), fallback to
> > Math::BigInt::Calc at -e line 1
>
> > What gives?
>
> You also need to install Math::BigInt::GMP and Math::BigInt::Pari. (I
> believe the former doesn't actually use the Math::GMP bindings at all,
> and instead links with the C library directly.)
Doh! OK, thanks.
------------------------------
Date: Wed, 28 Oct 2009 09:46:05 -0700 (PDT)
From: MaggotChild <hsomob1999@yahoo.com>
Subject: Net::SFTP Fails, sftp OK
Message-Id: <7b1ecafc-b68c-406e-a087-687ae805ff84@q40g2000prh.googlegroups.com>
This just fails unexpectedly. With sftp I can connect no problem:
perl -MNet::SFTP -le'$ftp = Net::SFTP->new("sftp.xj999.com", user =>
"X", password => "Z", debug => 1); print $_->{filename} for $ftp->ls;'
localhost: Reading configuration data /mounts/sysadm/xj/.ssh/config
localhost: Reading configuration data /etc/ssh_config
localhost: Connecting to sftp.xj999.com, port 22.
localhost: Remote protocol version 2.0, remote software version
5.1.3.8 SSH Tectia Server
localhost: Net::SSH::Perl Version 1.34, protocol version 2.0.
localhost: No compat match: 5.1.3.8 SSH Tectia Server
localhost: Connection established.
localhost: Sent key-exchange init (KEXINIT), wait response.
localhost: Algorithms, c->s: 3des-cbc hmac-sha1 none
localhost: Algorithms, s->c: 3des-cbc hmac-sha1 none
localhost: Entering Diffie-Hellman Group 1 key exchange.
Broken Pipe
I had some trouble installing Net::SFTP, so I figured maybe it was
the install but, on another machine:
localhost: Reading configuration data /home/xj/.ssh/config
localhost: Reading configuration data /etc/ssh_config
localhost: Connecting to sftp.xj999.com, port 22.
localhost: Remote version string: SSH-2.0-5.1.3.8 SSH Tectia Server
localhost: Remote protocol version 2.0, remote software version
5.1.3.8 SSH Tectia Server
localhost: Net::SSH::Perl Version 1.30, protocol version 2.0.
.ocalhost: No compat match: 5.1.3.8 SSH Tectia Server
localhost: Connection established.
localhost: Sent key-exchange init (KEXINIT), wait response.
Connection closed by remote host. at /usr/lib/perl5/site_perl/5.8.8/
Net/SSH/Perl/Kex.pm line 142
These are both v0.10
Also, what's up with the SFTP docs -they suck! Does new() die? How do
I cd, can I cd? How do I close the connection?
Thanks
------------------------------
Date: Wed, 28 Oct 2009 10:13:31 -0700 (PDT)
From: MaggotChild <hsomob1999@yahoo.com>
Subject: Re: Net::SFTP Fails, sftp OK
Message-Id: <fa4bf688-e5ee-4af6-9523-2000bd843b0e@y32g2000prd.googlegroups.com>
On Oct 28, 8:46=A0am, MaggotChild <hsomob1...@yahoo.com> wrote:
> This just fails unexpectedly. With sftp I can connect no problem:
>
> =A0perl -MNet::SFTP -le'$ftp =3D Net::SFTP->new("sftp.xj999.com", user =
=3D>
> "X", password =3D> "Z", debug =3D> 1); print $_->{filename} for $ftp->ls;=
'
> localhost: Reading configuration data /mounts/sysadm/xj/.ssh/config
> localhost: Reading configuration data /etc/ssh_config
> localhost: Connecting to sftp.xj999.com, port 22.
> localhost: Remote protocol version 2.0, remote software version
> 5.1.3.8 SSH Tectia Server
> localhost: Net::SSH::Perl Version 1.34, protocol version 2.0.
> localhost: No compat match: 5.1.3.8 SSH Tectia Server
> localhost: Connection established.
> localhost: Sent key-exchange init (KEXINIT), wait response.
> localhost: Algorithms, c->s: 3des-cbc hmac-sha1 none
> localhost: Algorithms, s->c: 3des-cbc hmac-sha1 none
> localhost: Entering Diffie-Hellman Group 1 key exchange.
> Broken Pipe
Trying to use version SSH 1 I get:
Can't locate object method "_session_channel" via package
"Net::SSH::Perl::SSH1" at /usr/lib/perl5/site_perl/5.8.8/Net/SFTP.pm
line 78.
maybe *both* my installs are screwed up.
------------------------------
Date: Wed, 28 Oct 2009 09:42:32 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Perl bioinformatics
Message-Id: <4ae803f9$0$83239$e4fe514c@news.xs4all.nl>
Keith Bradnam wrote:
> I co-teach a Unix & Perl course at UC Davis that is aimed at teaching
> graduate students how to learn the basics of Perl in a biological
> context. We have specifically tried to assume no prior knowledge of
> programming as many people who take our course are new to this.
>
> We have made our course materials (data & documentation) freely
> available to anyone else who is interested:
>
> http://korflab.ucdavis.edu/Unix_and_Perl/index.html
>
> There is a corresponding Google Group for discussion of issues arising
> from the course. We also make regular updates to the documentation.
> Hope this might be of use to you.
I Like It.
--
Ruud
------------------------------
Date: Wed, 28 Oct 2009 07:56:05 -0700 (PDT)
From: x yf <scriptdevsupport@gmail.com>
Subject: Perl IDE ScriptDev V2.3 released
Message-Id: <684d9807-16b3-469f-86cb-f95043bff1a6@v15g2000prn.googlegroups.com>
ScriptDev is developed by a powerful scripting language integrated
development environment(IDE), can be used for Python, Ruby, Lua, Tcl,
Perl, etc. scripting language, such as the development and debugging.
ScriptDev similar to the components of the Eclipse framework to
support the expansion of rich, Users can also follow their own
ScriptDev the development of standardized components to various types
of plug-ins to enhance the functions of platform.
you can find out and download it from http://www.scriptdevelop.com
Main features:
*Edit, debug, run tcl, python, ruby, perl, lua scripts;
*Script compiler / encryption and generate an executable file (the
script for each different level of support);
*Analysis of efficiency function as (the script for each different
level of support);
*Keyword help, through the F1 key or move the mouse to the keyword,
access to detailed information to help;
*Collected more script extension, to help document and presentation
process, in addition to the commonly used tk, wx, pmw, there are
images, multimedia, the interface, and many other variety of
extensions;
*A flexible, scalable architecture, the entire system can be flexible
interpretation of the expansion of various components, interface
components, tools, interface style;
*Console support functions (currently only tcl console, telnet
console, serial console available);
*Packaging TclFace pages expansion of the package, can be the object-
oriented tcl script development platform available in this script
pages;
*Interface support for skin, support Office2007, Visual Studio 2005,
and other interface style.
------------------------------
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 2654
***************************************