[31051] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2296 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 25 14:09:51 2009

Date: Wed, 25 Mar 2009 11:09:14 -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, 25 Mar 2009     Volume: 11 Number: 2296

Today's topics:
    Re: calculate an average with every data in an array <jogsalot75@yahoo.de>
    Re: Debian MySQL Perl  DBI - connection terminates unex sln@netherlands.com
        How to sleep less then 1 second <tower.grv@gmail.com>
    Re: How to sleep less then 1 second (Jens Thoms Toerring)
    Re: How to sleep less then 1 second <hjp-usenet2@hjp.at>
    Re: How to sleep less then 1 second <jurgenex@hotmail.com>
    Re: How to sleep less then 1 second <smallpond@juno.com>
        Invoking an SSH client by clicking a URL Link cyrusgreats@gmail.com
        PPM error message -- invalid token <cartercc@gmail.com>
    Re: PPM error message -- invalid token <smallpond@juno.com>
    Re: PPM error message -- invalid token <hjp-usenet2@hjp.at>
        RTF to HTML conversion grouchy.oldgit@googlemail.com
    Re: RTF to HTML conversion <jkorpela@cs.tut.fi>
        Sharing BerkeleyDB among forked children <liarafan@xs4all.nl>
        Typeglobs vs References <schaitan@gmail.com>
    Re: Typeglobs vs References sln@netherlands.com
    Re: Typeglobs vs References <schaitan@gmail.com>
    Re: what is the return value type of !1 ? (Tim McDaniel)
    Re: what is the return value type of !1 ? <ben@morrow.me.uk>
    Re: what is the return value type of !1 ? <tadmc@seesig.invalid>
        XML::Reader - request for comments <klaus03@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 25 Mar 2009 07:19:02 -0700 (PDT)
From: Erol Akman <jogsalot75@yahoo.de>
Subject: Re: calculate an average with every data in an array
Message-Id: <92a1b739-02db-4e12-b1b3-d546d0efca64@c9g2000yqm.googlegroups.com>

Hi Darrin,

thank you very much for your reply and your script. It works very well
and made realize, that my problem is hard to solve.

Thx

-----
Erol


------------------------------

Date: Wed, 25 Mar 2009 08:23:13 GMT
From: sln@netherlands.com
Subject: Re: Debian MySQL Perl  DBI - connection terminates unexpectedly after 100 secs.
Message-Id: <48qjs4pvncm15c1p79k32urmvenliido96@4ax.com>

On Wed, 25 Mar 2009 07:01:38 -0000, "John" <john1949@yahoo.com> wrote:

>
>"Jens Thoms Toerring" <jt@toerring.de> wrote in message 
>news:727ga0Fo7qv3U1@mid.uni-berlin.de...
>> John <john1949@yahoo.com> wrote:
>>
>>> "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote in message
>>> news:49be71fd$0$89873$815e3792@news.qwest.net...
>>> > John wrote:
>>> >> I'm updating a MySQL table with about 2 million records.  After about 
>>> >> 100
>>> >> seconds the program ends with no error message.  If I use LIMIT
>>> >> 800000,50000 the part where it stopped is OK so the UPDATE part is OK.
>>> >>
>>> >> Is there a time out parameter?  Or am I running out of memory.  Can 
>>> >> the
>>> >> memory be increased?
>>> >
>>> > Check line 24.
>>
>>> Line 24 says:-
>>
>>> our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
>>> socket hot
>>
>>> Can't see how that can affect it.
>>
>> I rather guess it was a gentle hint that your problem description
>> is too vague to allow to deduce what's going wrong. But your sub-
>> ject line may contain a hint: it looks as if the update is done
>> from within a CGI script or something similar, running on a web
>> server. And normally there's a CPU time limit set for such scripts
>> to catch e.g. script that run in an endless loop. That's what I
>> would check for first (note: if it's not set then an OS default
>> limit may be used!). If you are using Apache it might be a RLimitCPU
>> directive. But there could also be a limit on the memory consumption
>> of such scripts (RLimitMEM with Apache2)... Perhaps a look at the log
>> files of the web server will give you some more hints.
>>
>>                             Regards, Jens
>> -- 
>>  \   Jens Thoms Toerring  ___      jt@toerring.de
>>   \__________________________      http://toerring.de
>
>Many thanks.  That was very helpful.  I have maxed both RLimitCPU and 
>RLimitMEM in Apache2 and that has had led to better performance.  There are 
>severe problems in using MySQL when you start hitting more than 2 million 
>rows irrespective how well you tweak your settings.
>
>Regards
>John
>
>
I am for hire. I've never done your fancy server names stuff.
But I can assure you I am an expert at Data Base and Perl.
The learning curve is like the next day.

Pay me and you get quality software! Price's are negotiable.
I'm looking for full-time at 140K but will work at $120/hr at
minimal time.

-sln


------------------------------

Date: Wed, 25 Mar 2009 07:57:43 -0700 (PDT)
From: "tower.grv@gmail.com" <tower.grv@gmail.com>
Subject: How to sleep less then 1 second
Message-Id: <f3651cf5-1695-4034-8ffd-337f97237900@c9g2000yqm.googlegroups.com>

Hello.
I want my Perl script execute some code in the begining of each
second.

I have code
----------------------------------------------------
#!/usr/bin/perl -w
my $thistime=time();
while(1){

while(time()-$thistime<1) {my $a=1;}

$thistime=time();
print $thistime."\n";
#some more code

}
----------------------------------------------------
This code works but it takes a lot of CPU resources.
sleep(1) is not good for me. Usually it is needed to sleep less then
second.

Is it possible to replace line
              while(time()-$thistime<1) {my $a=1;}
with better code?


------------------------------

Date: 25 Mar 2009 15:17:01 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: How to sleep less then 1 second
Message-Id: <72v07dFs8qolU1@mid.uni-berlin.de>

tower.grv@gmail.com <tower.grv@gmail.com> wrote:
> I want my Perl script execute some code in the begining of each
> second.

> I have code
> ----------------------------------------------------
> #!/usr/bin/perl -w
> my $thistime=time();
> while(1){

> while(time()-$thistime<1) {my $a=1;}

> $thistime=time();
> print $thistime."\n";
> #some more code

> }
> ----------------------------------------------------
> This code works but it takes a lot of CPU resources.
> sleep(1) is not good for me. Usually it is needed to sleep less then
> second.

> Is it possible to replace line
>               while(time()-$thistime<1) {my $a=1;}
> with better code?

Yes. Use e.g.

select( undef, undef, undef, $delay );

where $delay is the time (in seconds but with sub-second resolution)
you want your process to sleep.
                                  Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


------------------------------

Date: Wed, 25 Mar 2009 16:25:50 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How to sleep less then 1 second
Message-Id: <slrngskj7u.gr0.hjp-usenet2@hrunkner.hjp.at>

On 2009-03-25 14:57, tower.grv@gmail.com <tower.grv@gmail.com> wrote:
> This code works but it takes a lot of CPU resources.
> sleep(1) is not good for me. Usually it is needed to sleep less then
> second.

See Time::HiRes

	hp


------------------------------

Date: Wed, 25 Mar 2009 09:11:54 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to sleep less then 1 second
Message-Id: <uslks4t1upi1n6ui1ub847ftb8vbq9m0u6@4ax.com>

"tower.grv@gmail.com" <tower.grv@gmail.com> wrote:
>sleep(1) is not good for me. Usually it is needed to sleep less then
>second.

You may want to check the FAQ: "perldoc -f second"

	How can I sleep() or alarm() for under a second?

jue


------------------------------

Date: Wed, 25 Mar 2009 10:51:57 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: How to sleep less then 1 second
Message-Id: <751ff2dd-e16b-4195-b7be-66fd8af535e8@e24g2000vbe.googlegroups.com>

On Mar 25, 10:57 am, "tower....@gmail.com" <tower....@gmail.com>
wrote:
> Hello.
> I want my Perl script execute some code in the begining of each
> second.
>
> I have code
> ----------------------------------------------------
> #!/usr/bin/perl -w
> my $thistime=time();
> while(1){
>
> while(time()-$thistime<1) {my $a=1;}
>
> $thistime=time();
> print $thistime."\n";
> #some more code
>
> }
>
> ----------------------------------------------------
> This code works but it takes a lot of CPU resources.
> sleep(1) is not good for me. Usually it is needed to sleep less then
> second.
>
> Is it possible to replace line
>               while(time()-$thistime<1) {my $a=1;}
> with better code?

TMTOWTDI
Tk has a millisecond timer.

#!/usr/bin/perl
use warnings;
use strict;

use Tk;
my $w = MainWindow->new();
my $times = 10;

sub do_stuff {
   print "doing $times\n";
   $w->destroy if $times-- == 0;
}

$w->repeat(1000, \&do_stuff);
MainLoop();


------------------------------

Date: Wed, 25 Mar 2009 10:52:22 -0700 (PDT)
From: cyrusgreats@gmail.com
Subject: Invoking an SSH client by clicking a URL Link
Message-Id: <40a1b8a2-4e2f-49a6-a0d6-4729c29e8f53@d19g2000prh.googlegroups.com>

Doe anyone know how to invoke an SSH client by clicking a URL Link.
I'm working on web page and wrote some perl cgi and I need to invoke
an ssh to send command to ssh server or client!
Thanks in advance..


------------------------------

Date: Wed, 25 Mar 2009 08:06:47 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: PPM error message -- invalid token
Message-Id: <539257d3-73cd-4574-bfa3-f4948c4db5ab@p11g2000yqe.googlegroups.com>

Attempting to install GD::Graph with PPM, got the following error
message (copied here in fulll)

<quote>
ppm> install GD::Graph
error: can't parse
  <SOFTPKG NAME="autorequire" VERSION="0,08,0,0">
    <TITLE>autorequire</TITLE>
    <ABSTRACT>Generate module code on demand</ABSTRACT>
    <AUTHOR>Patrick LeBoutillier &lt;patl@cpan.org&gt;</AUTHOR>
  </SO</SOFTPKG>:
not well-formed (invalid token) at line 6, column 6, byte 213 at C:/
Perl/site/lib/XML/Parser.pm line
 187

C:\Perl>
</quote>

I looked at Perser.pm and found nothing to fix. What's wrong, and how
can I fix it? If anyone knows.

Thanks, CC.


------------------------------

Date: Wed, 25 Mar 2009 08:41:30 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: PPM error message -- invalid token
Message-Id: <a2e46d3c-6834-4cf8-8e1c-ce0113d7949f@f11g2000vbf.googlegroups.com>

On Mar 25, 11:06 am, ccc31807 <carte...@gmail.com> wrote:
> Attempting to install GD::Graph with PPM, got the following error
> message (copied here in fulll)
>
> <quote>
> ppm> install GD::Graph
> error: can't parse
>   <SOFTPKG NAME="autorequire" VERSION="0,08,0,0">
>     <TITLE>autorequire</TITLE>
>     <ABSTRACT>Generate module code on demand</ABSTRACT>
>     <AUTHOR>Patrick LeBoutillier &lt;p...@cpan.org&gt;</AUTHOR>
>   </SO</SOFTPKG>:
> not well-formed (invalid token) at line 6, column 6, byte 213 at C:/
> Perl/site/lib/XML/Parser.pm line
>  187
>
> C:\Perl>
> </quote>
>
> I looked at Perser.pm and found nothing to fix. What's wrong, and how
> can I fix it? If anyone knows.
>
> Thanks, CC.

Why would Parser.pm have a problem?
It's telling you the exact byte in your ppm file that has a problem.
My guess would be an illegal character.  XML can be picky.


------------------------------

Date: Wed, 25 Mar 2009 16:42:33 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: PPM error message -- invalid token
Message-Id: <slrngskk7a.gr0.hjp-usenet2@hrunkner.hjp.at>

On 2009-03-25 15:06, ccc31807 <cartercc@gmail.com> wrote:
><quote>
> ppm> install GD::Graph
> error: can't parse
>  <SOFTPKG NAME="autorequire" VERSION="0,08,0,0">
>     <TITLE>autorequire</TITLE>
>     <ABSTRACT>Generate module code on demand</ABSTRACT>
>     <AUTHOR>Patrick LeBoutillier &lt;patl@cpan.org&gt;</AUTHOR>
>  </SO</SOFTPKG>:
> not well-formed (invalid token) at line 6, column 6, byte 213 at C:/
> Perl/site/lib/XML/Parser.pm line
>  187
>
> C:\Perl>
></quote>
>
> I looked at Perser.pm and found nothing to fix.

If a program complains about the format of a data file, it isn't always
the program which is wrong. In this case it is the data file:

>  </SO</SOFTPKG>:

I agree with XML::Parser that this isn't well-formed XML.

	hp


------------------------------

Date: Wed, 25 Mar 2009 03:48:38 -0700 (PDT)
From: grouchy.oldgit@googlemail.com
Subject: RTF to HTML conversion
Message-Id: <12805874-268d-4ac7-beae-0f1c6e6384df@o36g2000yqh.googlegroups.com>

Does anyone know of a good, free RTF to (X)HTML conversion utility?
Does not need to convert images / tables etc, just capture <p>,
<strong>, <em>.


------------------------------

Date: Wed, 25 Mar 2009 17:58:08 +0200
From: "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Subject: Re: RTF to HTML conversion
Message-Id: <6xsyl.4185$_f7.2726@uutiset.elisa.fi>

grouchy.oldgit@googlemail.com wrote:

> Does anyone know of a good, free RTF to (X)HTML conversion utility?
> Does not need to convert images / tables etc, just capture <p>,
> <strong>, <em>.

Google for rtf2html.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/


------------------------------

Date: Wed, 25 Mar 2009 16:21:54 +0100
From: "Mark" <liarafan@xs4all.nl>
Subject: Sharing BerkeleyDB among forked children
Message-Id: <0JqdnWjvc7mT0VfUnZ2dnUVZ8tyWnZ2d@giganews.com>

Hello,

Using BerkeleyDB in Perl 5.8.8 on a FreeBSD system, I am applying its tied
hashes inside forked children of a daemon, as a means of IPC. This works
great, except that for every child, when it forks, I currently set the
environment and initialize the databases, like:

if (not eval {$env = new BerkeleyDB::Env
        -Cachesize => 16777216,
        -Home      => '/var/db/Berkeley',
        -Flags     => DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL}) {
    log_error ((($_ = $BerkeleyDB::Error) ? ($_) : ($!)));
} elsif (not eval {tie %whitelisted, 'BerkeleyDB::Hash',

 ...

Etc. I wonder, is this really necessary? For one, I'm thinking it wreaks
havoc on the Cache, as re-initializing a cache for each child seems rather
pointless under these circumstances. Could I not just tie these databases
in the parent once, and then reuse them per child? I know for MySQL
connections this certainly goes wrong.

My main point just is, that I would like to retain the use of a shared
Cache among the forking children. If anyone knows how to do such a thing,
I'd appreciate hearing about it.

Thanks.


------------------------------

Date: Wed, 25 Mar 2009 01:58:14 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Typeglobs vs References
Message-Id: <66ac7bb3-6672-4551-8c54-5e0e6da92a18@b9g2000prd.googlegroups.com>

Hi, i've been reading Programming in Perl and perldata, perlref, etc
for understanding typeglobs and how they relate to references.
Frankly, i found the material a bit daunting for someone who's just
started in perl. In many places, I found statements to the effect that
typeglobs and references can be used interchangeably. How is this
possible? Can any1 pls point me to easier articles/tutorials which
give a step-by-step explanation? any examples that you can rig up to
clarify this?

Thanks a lot...


------------------------------

Date: Wed, 25 Mar 2009 09:27:42 GMT
From: sln@netherlands.com
Subject: Re: Typeglobs vs References
Message-Id: <92ujs4db4qut49691bqf7ks5u05ip271hj@4ax.com>

On Wed, 25 Mar 2009 01:58:14 -0700 (PDT), Krishna Chaitanya <schaitan@gmail.com> wrote:

>Hi, i've been reading Programming in Perl and perldata, perlref, etc
>for understanding typeglobs and how they relate to references.
>Frankly, i found the material a bit daunting for someone who's just
>started in perl. In many places, I found statements to the effect that
>typeglobs and references can be used interchangeably. How is this
>possible? Can any1 pls point me to easier articles/tutorials which
>give a step-by-step explanation? any examples that you can rig up to
>clarify this?
>
>Thanks a lot...

Why don't you stay away from typeglobs. Then you understand references 
completely and are now moving on to typeglobs as a beginniner, or have you
learned typeglobs first?

-sln


------------------------------

Date: Wed, 25 Mar 2009 08:18:01 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Typeglobs vs References
Message-Id: <eb0f0b8f-7031-42de-b8f4-a1582f6db453@a5g2000pre.googlegroups.com>

Learned references and their uses in creating data structures. Now
moving onto typeglobs...


------------------------------

Date: Wed, 25 Mar 2009 15:11:20 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: what is the return value type of !1 ?
Message-Id: <gqdhio$j52$1@reader1.panix.com>

In article <slrngsjaq7.a7i.nospam-abuse@chorin.math.berkeley.edu>,
Ilya Zakharevich  <nospam-abuse@ilyaz.org> wrote:
>On 2009-03-24, Tim McDaniel <tmcd@panix.com> wrote:
>> That can be stated more precisely.  Luckily, "man perlsyn" does.
>
>... wrongly (as goes with the most of current Perl docs)...
>
>> There are actually 5 things that are treated as false in a boolean
>> context, and !(something true) has a special value:
>>
>>     Truth and Falsehood
>>
>>     The number 0, the strings '0' and '', the empty list "()", and
>>     "undef" are all false in a boolean context.  All other values
>>     are true.
>
>Wrong.

I would like to learn more about Perl, so would you please explain
what is correct?

>>     Negation of a true value by "!" or "not" returns a special
>>     false value.  When evaluated as a string it is treated as '',
>>     but as a number, it is treated as 0.
>
>There is nothing especially "special" about the returned value
>(unless one noticed that it is the same value for all statements
>returning FALSE).

Well, as the examples showed, the value prints as a null string --
but, unlike "", it does not throw a warning under "-w" when used in
arithmetic.  I don't know of any other value that has those
properties.  Why do you write that it's not "special"?

-- 
Tim McDaniel, tmcd@panix.com


------------------------------

Date: Wed, 25 Mar 2009 16:27:09 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: what is the return value type of !1 ?
Message-Id: <tj2q96-gm1.ln1@osiris.mauzo.dyndns.org>


Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2009-03-24, Tim McDaniel <tmcd@panix.com> wrote:
> 
> >     Negation of a true value by "!" or "not" returns a special
> >     false value.  When evaluated as a string it is treated as '', but
> >     as a number, it is treated as 0.
> 
> There is nothing especially "special" about the returned value (unless
> one noticed that it is the same value for all statements returning FALSE).

Well, it's a dualvar, which is reasonably special. It is possible to
create an equivalent dualvar with

    use Scalar::Util;

    my $false = dualvar 0, "";

Ben



------------------------------

Date: Wed, 25 Mar 2009 11:59:04 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: what is the return value type of !1 ?
Message-Id: <slrngskomo.3mr.tadmc@tadmc30.sbcglobal.net>

Tim McDaniel <tmcd@panix.com> wrote:
> In article <slrngsjaq7.a7i.nospam-abuse@chorin.math.berkeley.edu>,
> Ilya Zakharevich  <nospam-abuse@ilyaz.org> wrote:
>>On 2009-03-24, Tim McDaniel <tmcd@panix.com> wrote:
>>> That can be stated more precisely.  Luckily, "man perlsyn" does.
>>
>>... wrongly (as goes with the most of current Perl docs)...
>>
>>> There are actually 5 things that are treated as false in a boolean
                       ^^^^^^^^
>>> context, and !(something true) has a special value:
>>>
>>>     Truth and Falsehood
>>>
>>>     The number 0, the strings '0' and '', the empty list "()", and
                                              ^^^^^^^^^^^^^^^^^^^
>>>     "undef" are all false in a boolean context.  All other values
>>>     are true.
>>
>>Wrong.
>
> I would like to learn more about Perl, so would you please explain
> what is correct?


I dunno if this is what Ilya had in mind, but the empty list
is most certainly not a false value.

Boolean context is a (special kind of) scalar context 

    unless ( warn wantarray ? "list context\n" : "scalar context\n" ) {
        print "false value\n";
    }

    (prints only "scalar context")

and

    there's no such thing as a list in scalar context (perlfaq4.pod)

eg.

    unless ( () ) {
        print "false value\n";
    }

There is no empty list there, merely some parenthesis.

(parens are not a "list constructor". You very often see lists in
 parens but that is for precedence reasons.
)


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Wed, 25 Mar 2009 05:43:41 -0700 (PDT)
From: Klaus <klaus03@gmail.com>
Subject: XML::Reader - request for comments
Message-Id: <51f9db34-069f-445a-87dc-61cd0dcd424b@y9g2000yqg.googlegroups.com>

I have released the module XML::Reader to CPAN:
see http://search.cpan.org/~keichner/XML-Reader-0.01/

I would like to ask for comments, suggestions, improvements, code-
reviews, etc... for that module.

--
Klaus


------------------------------

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 2296
***************************************


home help back first fref pref prev next nref lref last post