[30754] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1999 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 23 11:09:44 2008

Date: Sun, 23 Nov 2008 08:09:11 -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           Sun, 23 Nov 2008     Volume: 11 Number: 1999

Today's topics:
    Re: atoi/atof <hjp-usenet2@hjp.at>
    Re: DBD::Pg installation under Vista <m.rombach89@googlemail.com>
    Re: Dose package name has to be the same as the filenam <hjp-usenet2@hjp.at>
    Re: failed perl upgrade <spamtrap@dot-app.org>
    Re: How to find all the strings in a long that are at m <1usa@llenroc.ude.invalid>
    Re: How to find all the strings in a long that are at m <hjp-usenet2@hjp.at>
    Re: How to iterator array in order? <hjp-usenet2@hjp.at>
    Re: how to support delete of <directoryname> as well as <hjp-usenet2@hjp.at>
    Re: how to support delete of <directoryname> as well as <hjp-usenet2@hjp.at>
    Re: post increment or pre increment? <hjp-usenet2@hjp.at>
    Re: post increment or pre increment? <news123@free.fr>
    Re: sleep(30) hangs <hjp-usenet2@hjp.at>
    Re: sleep(30) hangs <hjp-usenet2@hjp.at>
    Re: sleep(30) hangs <news123@free.fr>
    Re: sleep(30) hangs <news123@free.fr>
    Re: use constant XX => ( ... <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 23 Nov 2008 09:20:07 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: atoi/atof
Message-Id: <slrngii4hp.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-23 07:17, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> [A complimentary Cc of this posting was NOT [per weedlist] sent to
> Peter J. Holzer
><hjp-usenet2@hjp.at>], who wrote in article <slrngigqpd.s9a.hjp-usenet2@hrunkner.hjp.at>:
>> > Nope, Perl's semantic coincides (unfortunately!) with sprintf()'s
>> > one.  It may have its own implementation of sprintf(), but no more
>> > than that...
>
>> I may be overlooking something obvious, but which format option will
>> produce the same output as perl's float->string conversion?
>
> Probably %g with precision governed by $#, IIRC.

I thought %.15g would fill with zeros, like %.15f does, but it doesn't.
My C is obviously getting rusty :-(.

So, yes, you're right. Perl mimics sprintf.

	hp


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

Date: Sun, 23 Nov 2008 03:05:58 -0800 (PST)
From: Martin Rombach <m.rombach89@googlemail.com>
Subject: Re: DBD::Pg installation under Vista
Message-Id: <33ee8387-35ab-4b59-85ba-0fa2f61e2511@x14g2000yqk.googlegroups.com>

Hey Rob,
> Do you have any additional info on the "R6034" error. (I don't know
> what that is.)
Runtime Error!
Program: C:\Perl\bin\perl.exe
R6034
An application has made an attempt to load the C runtime library
incorrectly. Please contact the applications's support team for more
information.

And Perl shouts:
install_driver(Pg) failed: Can't load 'C:/Perl/site/lib/auto/DBD/Pg/
Pg.dll' for
module DBD::Pg: load_file:Eine DLL-Initialisierungsroutine ist
fehlgeschlagen [[in English: "dll initialization routine failed"]] at
 C:/Perl/lib/DynaLoader.pm line 202.
 at (eval 9) line 3
Compilation failed in require at (eval 9) line 3.
Perhaps a required shared library or dll isn't installed where
expected
 at test.pl line 14

> As regards the pg.dll.manifest, could it be that it needs to be placed
> in perl/site/bin instead of perl/bin ? (It probably depends upon where
> pg.dll is located.)
Yes, thats right. pg.dll.manifest is placed in C:/Perl/site/lib/auto/
DBD/Pg/. I copied it to C:/Perl/bin and renamed it into
Perl.exe.manifest (i forgot to say that, sorry). I got that tip from
the internet and it worked fine on my XP-Machine, but not on Vista.

Cheers,
Martin



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

Date: Sun, 23 Nov 2008 11:30:36 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Dose package name has to be the same as the filename? (for OO)
Message-Id: <slrngiic6e.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-21 03:54, Peng Yu <PengYu.UT@gmail.com> wrote:
> On Nov 20, 9:22 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
>> So no, it's not required in theory. But the convention of naming them
>> the same is followed so widely, that in practice it's really more or
>> less required.
>
> Therefore, in one file, only one package can be defined practically,
> right? If that is the case, why we still need to have the keyword
> 'package'? Why perl not just use the file name as the package name?

No. You can have multiple packages in one file. For example, if you have 
Foo.pm:

package Foo;
 ...
package Foo::Bar;
 ...
package Some::Other::Class::Related::To::Foo;
 ...
__END__

you can load it with "use Foo". Only the import method of "Foo" (if any)
will be called, but all three packages will be loaded and are available
in your program. So you can then call
Some::Other::Class::Related::To::Foo->new() if you want. But you cannot
"use Some::Other::Class::Related::To::Foo", because no file
Some/Other/Class/Related/To/Foo.pm exists - you have to "use Foo" to
load it. Sometimes it makes sense to put several packages into a single
file. But (apart from aesthetic reasons) only rarely - I think I needed
that maybe 2 or 3 times in over 10 years of Perl programming.

	hp


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

Date: Sun, 23 Nov 2008 07:20:57 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: failed perl upgrade
Message-Id: <m18wrafxau.fsf@dot-app.org>

afith13@gmail.com writes:

> I just started learning perl and I currently have perl 5.8.8 installed
> on mac os x 10.5.5.

If you're just starting, that's good enough. Installing a new Perl is
"running" - learn to walk first.

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Sun, 23 Nov 2008 13:44:02 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to find all the strings in a long that are at most of n  different characters of a test string?
Message-Id: <Xns9B5F58D636123asu1cornelledu@127.0.0.1>

"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote in
news:slrngii9lo.3q8.hjp-usenet2@hrunkner.hjp.at: 

>>> >On Nov 20, 3:46 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid>
>>> >wrote: 
>>> >> I looked at the perldoc perlvar page to remind myself what it
>>> >> said. I am unable to figure out how one could make it clearer:
> 
> Did you quote from a newer version than 5.10.0? It's slightly
> different in my docs (only checked 5.8.8 and 5.10.0).

C:\Documents and Settings\asu1> perl -v

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
(with 5 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 1004 [287188] provided by ActiveState 
http://www.ActiveState.com
Built Sep  3 2008 13:16:37

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Sun, 23 Nov 2008 10:47:35 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <slrngii9lo.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-21 05:08, Peng Yu <PengYu.UT@gmail.com> wrote:
> On Nov 20, 9:06 pm, Jürgen Exner <jurge...@hotmail.com> wrote:
>> Peng Yu <PengYu...@gmail.com> wrote:
>> >On Nov 20, 3:46 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>> >> I looked at the perldoc perlvar page to remind myself what it said. I am
>> >> unable to figure out how one could make it clearer:

Did you quote from a newer version than 5.10.0? It's slightly different
in my docs (only checked 5.8.8 and 5.10.0).

>> >Thank you the example. I see what it means. In general, I think the
>> >document can be made easier to read with more examples.
>>
>> But there are examples in that section:
>> <quote>
>>             After a match against some variable $var:
>>
>>             "$`" is the same as "substr($var, 0, $-[0])"
>>             "$&" is the same as "substr($var, $-[0], $+[0] - $-[0])"
>>             "$'" is the same as "substr($var, $+[0])"
>>             "$1" is the same as "substr($var, $-[1], $+[1] - $-[1])"
>>             "$2" is the same as "substr($var, $-[2], $+[2] - $-[2])"
>>             "$3" is the same as "substr $var, $-[3], $+[3] - $-[3])"
>> </quote>
>
> I didn't understand the above examples because it refers to $-[0],
> which was exactly what I wanted to understand.

If it didn't contain $-[0], it wouldn't be an example for the use of
$-[0], would it? 

> I agree your points. But I think that the perldoc shall have as less
> cyclic references as possible. If the example that you mentioned in
> the perldoc is not cyclic referred, it would easier to read.

I don't see any cyclic references in the section about @-. $-[0] is
explained in the very first sentence:

       @-      $-[0] is the offset of the start of the last successful match.

To understand the examples, it helps to know what $`, $&, etc. are.
These are explained elsewhere in the same document, and none of them
is explained by referring to @-. No cycles there.

	hp


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

Date: Sun, 23 Nov 2008 12:25:03 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How to iterator array in order?
Message-Id: <slrngiifcg.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-21 05:30, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Peng Yu <PengYu.UT@gmail.com> wrote:
[...]
>>for($i = 0; $i <= $#array; ++ $i) {
>>    print "$array[$i]\n";
>>}
>
> This does something totally different because it iterates over the
> indices of the array. 
> BTW: if you are using $#array instead of the length of the array then
> you probably should also start your iteration with $[ instead of with 0.
> The combination you are using doesn't make much sense because your start
> value is hardcoded to ignores non-default values for $[ while your end
> respects them.

Frankly, in my world $[ doesn't exist. Anyone who sets it outside of an
obfu, should be drawn and quartered. I won't clutter up my code just
because some idiot might set it. So if I need to iterate over the
indices of an array I use:

    for my $i (0 .. $#array) { ... }

	hp


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

Date: Sun, 23 Nov 2008 10:04:37 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: how to support delete of <directoryname> as well as <directoryname>/
Message-Id: <slrngii755.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-19 11:20, mike <mikaelpetterson@hotmail.com> wrote:
> We are using a perl script to delete file/folder in apache ( cgi-bin).
>
> When we do a delete with and url that ends with <directoryname>/ the
> delete is performed.
> However when we use only <directoryname> without the slash then we get
> the response saying,
> Directory permanently moved.

You mean "301 Directory permanently moved." (the numeric code is an
important - often the most important - part of the HTTP response).

Most likely that reponse comes from the server. 

"http://www.example.com/directoryname" and
"http://www.example.com/directoryname/" are two different resources,
which must be treated differently. However, if "http://www.example.com/"
refers to a filesystem, and "directoryname/" refers to a directory in
that filesystem, then "http://www.example.com/directoryname" cannot
exist. Since users often omit the / at the end, most (all?) webservers
check for this case. "Let's see - the client requested "/directoryname",
but that doesn't exist. But I do have "/directoryname/", so it probably
wanted that. So I'll send a 301 response instead a 404 response".

This check probably happens before your script is called.

	hp


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

Date: Sun, 23 Nov 2008 10:17:52 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: how to support delete of <directoryname> as well as <directoryname>/
Message-Id: <slrngii7u1.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-19 13:05, Tad J McClellan <tadmc@seesig.invalid> wrote:
>> # Note: should also check we are an authentication user by checking
>> # REMOTE_USER
>
>
> That is not secure you know...

REMOTE_USER is set by the web server. You don't know how the web server
determined the remote user, so you cannot know whether it is secure.
Basic auth over an unencrypted connection is insecure, of course. Basic
auth over https cannot be sniffed on the network (but the user may have
a weak password, or a keylogger on his machine). Https with Public key
crypto where the private key is stored in key hardware token on the
user's side is very secure.

However, checking for REMOTE_USER is often futile: If the user wasn't
authenticated or isn't authorized to run the script, the script isn't
even called.

	hp


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

Date: Sun, 23 Nov 2008 12:14:21 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: post increment or pre increment?
Message-Id: <slrngiieoe.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-21 05:32, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Peng Yu <PengYu.UT@gmail.com> wrote:
>>I learned in C++, that it is better to use pre increment rather than
>>post increment. I'm wondering which one is better to use in perl, 
>
> It depends on what you want to do. In that expression, do you need the
> old value before the increment or the new value after the increment?

In the example he gave, he needs neither the old nor the new value. He
just needs the side effect. This is very common in C and C++, and the
only case where you pre- and postincrement are semantically equivalent,
so you can choose one or the other.

Pre-increment is semantically simpler. It increments the variable and
returns the new value. Post-increment needs to save the old value before
incrementing the variable, so that it can return the old value.

For simple variables this doesn't make any difference in C++, since the
compiler can just optimize the copy away. But for objects, it's not so
simple (the copy itself may cause some side-effect) so the usual advice
is to use pre-increment if you don't need the return value.

Perl has a very weak optimizer (because it needs to be fast), so
pre-increment might be faster.

>>example, in a for loop.
>>
>>for(my $i = 0; $i <10; ++ $i)
>>
>>or
>>
>>for(my $i = 0; $i <10; $i ++)
>>
>>Which one is better?

Why don't you just try it?

> Neither, nor. The best is a very simple and much more readable
>
> 	for my $i (0..9)

#!/usr/bin/perl
use warnings;
use strict;
use Benchmark qw(cmpthese);

use constant N => 10;

cmpthese (-5,
          {
            'pre'   => sub { for(my $i = 0; $i <N; ++ $i) {} },
            'post'  => sub { for(my $i = 0; $i <N; ++ $i) {} },
            'range' => sub { for my $i (0 .. N-1) {} },
          });
__END__

Oops, the range is consistently the slowest:

          Rate range  post   pre
range 667769/s    --   -7%   -7%
post  714756/s    7%    --   -1%
pre   721696/s    8%    1%    --

          Rate range  post   pre
range 634634/s    --   -8%   -9%
post  691932/s    9%    --   -0%
pre   694498/s    9%    0%    --

          Rate range  post   pre
range 636271/s    --  -14%  -19%
post  739517/s   16%    --   -6%
pre   786373/s   24%    6%    --

but let's try N => 100:

          Rate   pre  post range
pre   103353/s    --   -0%  -27%
post  103859/s    0%    --  -27%
range 141336/s   37%   36%    --

          Rate  post   pre range
post   91995/s    --   -8%  -34%
pre   100124/s    9%    --  -28%
range 140021/s   52%   40%    --

          Rate  post   pre range
post   96837/s    --   -7%  -31%
pre   103855/s    7%    --  -26%
range 140913/s   46%   36%    --

Now, using a range is the fastest version, and that advantage increases for larger loops:

N => 1000:

         Rate   pre  post range
pre   10094/s    --   -7%  -37%
post  10798/s    7%    --  -32%
range 15982/s   58%   48%    --

         Rate  post   pre range
post  10139/s    --   -2%  -35%
pre   10370/s    2%    --  -34%
range 15678/s   55%   51%    --

         Rate   pre  post range
pre   10647/s    --   -2%  -34%
post  10900/s    2%    --  -33%
range 16209/s   52%   49%    --

N => 10_000:

        Rate   pre  post range
pre    990/s    --  -10%  -38%
post  1099/s   11%    --  -31%
range 1597/s   61%   45%    --

        Rate  post   pre range
post   983/s    --   -5%  -39%
pre   1037/s    5%    --  -36%
range 1621/s   65%   56%    --

        Rate  post   pre range
post  1013/s    --   -3%  -38%
pre   1047/s    3%    --  -36%
range 1627/s   61%   55%    --

The difference between pre and post is generally small and sometimes pre
is faster and sometimes post is faster. So the difference between them
is probably less than the precision of the measurement. 

	hp

PS: On my system, for this simple loop, all three variants are the same
speed for N in (14 .. 20). For lower values, range is consistently
slower than pre or post, for larger values, it is consistently faster.
If you have a different version of perl, a different processor, or a
more complex loop, results may be different.

PPS: N-1 is optimized by the compiler, so that doesn't make a
difference.


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

Date: Sun, 23 Nov 2008 15:05:51 +0100
From: News123 <news123@free.fr>
Subject: Re: post increment or pre increment?
Message-Id: <49296340$0$8224$426a74cc@news.free.fr>

Hi Peter,

Is this a copy paste error?

You seem to test twice the pre-increment:

>           {
>             'pre'   => sub { for(my $i = 0; $i <N; ++ $i) {} },
>             'post'  => sub { for(my $i = 0; $i <N; ++ $i) {} },
>             'range' => sub { for my $i (0 .. N-1) {} },



I changed the script to make pre and psot different and to use N=100
instead of N=10.

Range is now sometimes faster then pre/post.
Apart from this still quite random:

$ perl bla.pl
     Rate   pre range  post
pre   69139/s    --  -14%  -18%
range 80766/s   17%    --   -4%
post  83995/s   21%    4%    --
$ perl bla.pl
         Rate  post   pre range
post  59401/s    --   -5%  -33%
pre   62784/s    6%    --  -29%
range 88636/s   49%   41%    --
$ perl bla.pl
         Rate   pre  post range
pre   60821/s    --   -1%  -27%
post  61321/s    1%    --  -26%
range 83067/s   37%   35%    --
$ perl bla.pl
         Rate   pre  post range
pre   58606/s    --   -2%  -33%
post  60009/s    2%    --  -31%
range 87417/s   49%   46%    --


bye


N
Peter J. Holzer wrote:
> On 2008-11-21 05:32, Jürgen Exner <jurgenex@hotmail.com> wrote:
>> Peng Yu <PengYu.UT@gmail.com> wrote:
>>> I learned in C++, that it is better to use pre increment rather than
>>> post increment. I'm wondering which one is better to use in perl, 
>> It depends on what you want to do. In that expression, do you need the
>> old value before the increment or the new value after the increment?
> 
> In the example he gave, he needs neither the old nor the new value. He
> just needs the side effect. This is very common in C and C++, and the
> only case where you pre- and postincrement are semantically equivalent,
> so you can choose one or the other.
> 
> Pre-increment is semantically simpler. It increments the variable and
> returns the new value. Post-increment needs to save the old value before
> incrementing the variable, so that it can return the old value.
> 
> For simple variables this doesn't make any difference in C++, since the
> compiler can just optimize the copy away. But for objects, it's not so
> simple (the copy itself may cause some side-effect) so the usual advice
> is to use pre-increment if you don't need the return value.
> 
> Perl has a very weak optimizer (because it needs to be fast), so
> pre-increment might be faster.
> 
>>> example, in a for loop.
>>>
>>> for(my $i = 0; $i <10; ++ $i)
>>>
>>> or
>>>
>>> for(my $i = 0; $i <10; $i ++)
>>>
>>> Which one is better?
> 
> Why don't you just try it?
> 
>> Neither, nor. The best is a very simple and much more readable
>>
>> 	for my $i (0..9)
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Benchmark qw(cmpthese);
> 
> use constant N => 10;
> 
> cmpthese (-5,
>           {
>             'pre'   => sub { for(my $i = 0; $i <N; ++ $i) {} },
>             'post'  => sub { for(my $i = 0; $i <N; ++ $i) {} },
>             'range' => sub { for my $i (0 .. N-1) {} },
>           });
> __END__
> 
> Oops, the range is consistently the slowest:
> 
>           Rate range  post   pre
> range 667769/s    --   -7%   -7%
> post  714756/s    7%    --   -1%
> pre   721696/s    8%    1%    --
> 
>           Rate range  post   pre
> range 634634/s    --   -8%   -9%
> post  691932/s    9%    --   -0%
> pre   694498/s    9%    0%    --
> 
>           Rate range  post   pre
> range 636271/s    --  -14%  -19%
> post  739517/s   16%    --   -6%
> pre   786373/s   24%    6%    --
> 
> but let's try N => 100:
> 
>           Rate   pre  post range
> pre   103353/s    --   -0%  -27%
> post  103859/s    0%    --  -27%
> range 141336/s   37%   36%    --
> 
>           Rate  post   pre range
> post   91995/s    --   -8%  -34%
> pre   100124/s    9%    --  -28%
> range 140021/s   52%   40%    --
> 
>           Rate  post   pre range
> post   96837/s    --   -7%  -31%
> pre   103855/s    7%    --  -26%
> range 140913/s   46%   36%    --
> 
> Now, using a range is the fastest version, and that advantage increases for larger loops:
> 
> N => 1000:
> 
>          Rate   pre  post range
> pre   10094/s    --   -7%  -37%
> post  10798/s    7%    --  -32%
> range 15982/s   58%   48%    --
> 
>          Rate  post   pre range
> post  10139/s    --   -2%  -35%
> pre   10370/s    2%    --  -34%
> range 15678/s   55%   51%    --
> 
>          Rate   pre  post range
> pre   10647/s    --   -2%  -34%
> post  10900/s    2%    --  -33%
> range 16209/s   52%   49%    --
> 
> N => 10_000:
> 
>         Rate   pre  post range
> pre    990/s    --  -10%  -38%
> post  1099/s   11%    --  -31%
> range 1597/s   61%   45%    --
> 
>         Rate  post   pre range
> post   983/s    --   -5%  -39%
> pre   1037/s    5%    --  -36%
> range 1621/s   65%   56%    --
> 
>         Rate  post   pre range
> post  1013/s    --   -3%  -38%
> pre   1047/s    3%    --  -36%
> range 1627/s   61%   55%    --
> 
> The difference between pre and post is generally small and sometimes pre
> is faster and sometimes post is faster. So the difference between them
> is probably less than the precision of the measurement. 
> 
> 	hp
> 
> PS: On my system, for this simple loop, all three variants are the same
> speed for N in (14 .. 20). For lower values, range is consistently
> slower than pre or post, for larger values, it is consistently faster.
> If you have a different version of perl, a different processor, or a
> more complex loop, results may be different.
> 
> PPS: N-1 is optimized by the compiler, so that doesn't make a
> difference.


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

Date: Sun, 23 Nov 2008 11:04:18 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: sleep(30) hangs
Message-Id: <slrngiial4.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-19 02:35, Petr Vileta (fidokomik) <stoupa@practisoft.cz> wrote:
> marathoner@sina.com wrote:
>> I have a programs that checks emails via IMAP and then sleeps for 30
>> seconds. Occasionally, it hangs on the line where it calls sleep(30).
>>
>> I use Perl 5.8.8 (ActivePerl Build 820) running on Windows 2000 SP4.
>>
>
> The reason is maybe that IMAP server need more time to logout user. I'm not 
> familiar with IMAP but my users which are using POP3 must leave 60 seconds time 
> space before he/she can login again.

How can this cause sleep to hang?

	hp


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

Date: Sun, 23 Nov 2008 11:10:06 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: sleep(30) hangs
Message-Id: <slrngiiavv.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-19 20:31, Ted Zlatanov <tzz@lifelogs.com> wrote:
> On Tue, 18 Nov 2008 08:01:00 -0800 (PST) marathoner@sina.com wrote: 

[with activestate perl on Windows 2000]


> m> I have a programs that checks emails via IMAP and then sleeps for 30
> m> seconds. Occasionally, it hangs on the line where it calls sleep(30).
> ...
> m> 	print "Done. See you in 30 seconds.\n\n\n";
> m> 	sleep(30); # <-- this is where it hangs sometimes
>
> sleep() may be interfering with other signal handlers.  Try 
> system(sleep => 30) instead to run it as a shell command; does that make
> a difference?

Does Windows 2000 have a sleep command? Windows 2003 doesn't:

| Microsoft Windows [Version 5.2.3790]
| (C) Copyright 1985-2003 Microsoft Corp.
| 
| C:\Dokumente und Einstellungen\hjp>sleep 30
| Der Befehl "sleep" ist entweder falsch geschrieben oder
| konnte nicht gefunden werden.

Translation: The command "sleep" is either misspelled or could not be
found.

	hp



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

Date: Sun, 23 Nov 2008 15:14:49 +0100
From: News123 <news123@free.fr>
Subject: Re: sleep(30) hangs
Message-Id: <49296559$0$8224$426a74cc@news.free.fr>

Ted might be rigth.

I never looked  at perl's implementation of sleep, but perhaps it's
implemented by settign an alarm and waiting for the alarm signal

If IMAP is messing around with signal handlers / alarms, then such
things might happen.

Perhaps you fall into a windows specific bug?

On unix I would propose to run your script with strace to check if
there's something weird to observe.

Does anybody know the Win2K equivalent of strace?

Perhaps this could give some ideas to Lei.



bye


N

Ted Zlatanov wrote:
> On Tue, 18 Nov 2008 08:01:00 -0800 (PST) marathoner@sina.com wrote: 
> 
> m> I have a programs that checks emails via IMAP and then sleeps for 30
> m> seconds. Occasionally, it hangs on the line where it calls sleep(30).
> ...
> m> 	print "Done. See you in 30 seconds.\n\n\n";
> m> 	sleep(30); # <-- this is where it hangs sometimes
> 
> sleep() may be interfering with other signal handlers.  Try 
> system(sleep => 30) instead to run it as a shell command; does that make
> a difference?
> 
> Ted


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

Date: Sun, 23 Nov 2008 15:34:21 +0100
From: News123 <news123@free.fr>
Subject: Re: sleep(30) hangs
Message-Id: <492969ee$0$10781$426a74cc@news.free.fr>

Just for info:


the perl script:
sleep(3)
sleep(3)


contained following in the strace output (linux):
> time(NULL)                              = 1227450756
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> nanosleep({2, 0}, {2, 0})               = 0
> time(NULL)                              = 1227450758
> time(NULL)                              = 1227450758
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> nanosleep({3, 0}, {3, 0})               = 0
> time(NULL)                              = 1227450761



News123 wrote:
> Ted might be rigth.
> 
> I never looked  at perl's implementation of sleep, but perhaps it's
> implemented by settign an alarm and waiting for the alarm signal
> 
> If IMAP is messing around with signal handlers / alarms, then such
> things might happen.
> 
> Perhaps you fall into a windows specific bug?
> 
> On unix I would propose to run your script with strace to check if
> there's something weird to observe.
> 
> Does anybody know the Win2K equivalent of strace?
> 
> Perhaps this could give some ideas to Lei.
> 
> 
> 
> bye
> 
> 
> N
> 
> Ted Zlatanov wrote:
>> On Tue, 18 Nov 2008 08:01:00 -0800 (PST) marathoner@sina.com wrote: 
>>
>> m> I have a programs that checks emails via IMAP and then sleeps for 30
>> m> seconds. Occasionally, it hangs on the line where it calls sleep(30).
>> ...
>> m> 	print "Done. See you in 30 seconds.\n\n\n";
>> m> 	sleep(30); # <-- this is where it hangs sometimes
>>
>> sleep() may be interfering with other signal handlers.  Try 
>> system(sleep => 30) instead to run it as a shell command; does that make
>> a difference?
>>
>> Ted


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

Date: Sun, 23 Nov 2008 09:47:33 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: use constant XX => ( ...
Message-Id: <slrngii655.3q8.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-19 10:06, Julian Lafontaine <nospam@nospam.com> wrote:
> There are two syntax for the "use constant" pragma: to declare a scalar 
> or to declare a list.
>
> use constant CONST => scalarvalue;

"scalarvalue" is a scalar.

> use constant LIST => qw( listitem1, listitem2, listitem3);

"qw( listitem1, listitem2, listitem3)" is a list (although it probably
doesn't contain the values you would expect).

> I've found this in a perl module :Win32::Exe.
> Could someone explain the syntax?
>
>
> use constant DISPATCH_TABLE => (
>      "PE\0\0"	=> "PE",
>      '*'		=> sub { die "Incorrect PE header -- not a valid .exe file" },
> );
>
> What is DISPATCH_TABLE: a scalar or a list?

What is 

    (
     "PE\0\0"	=> "PE",
     '*'		=> sub { die "Incorrect PE header -- not a valid .exe file" },
    )
?

A scalar or a list?



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

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


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