[31357] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2609 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 24 09:09:56 2009

Date: Thu, 24 Sep 2009 06:09:19 -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           Thu, 24 Sep 2009     Volume: 11 Number: 2609

Today's topics:
    Re: Active State 64-bit and Win32 Modules <pgodfrin@gmail.com>
    Re: Active State 64-bit and Win32 Modules <smallpond@juno.com>
    Re: Button in WWW::Mechanize <douglasg.wilson@gmail.com>
    Re: decimal round off issue <hjp-usenet2@hjp.at>
    Re: decimal round off issue sln@netherlands.com
    Re: decimal round off issue <hjp-usenet2@hjp.at>
    Re: decimal round off issue <ben@morrow.me.uk>
    Re: decimal round off issue <nospam-abuse@ilyaz.org>
    Re: decimal round off issue sln@netherlands.com
    Re: decimal round off issue sln@netherlands.com
    Re: decimal round off issue <ben@morrow.me.uk>
        FAQ 5.29 How can I read in a file by paragraphs? <brian@theperlreview.com>
        FAQ 7.13 What's a closure? <brian@theperlreview.com>
        FAQ 7.2 What are all these $@%&* punctuation signs, and <brian@theperlreview.com>
        FAQ 7.23 How do I create a switch or case statement? <brian@theperlreview.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 23 Sep 2009 01:10:34 -0700 (PDT)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: Active State 64-bit and Win32 Modules
Message-Id: <c9ea57be-3d75-4f01-8050-f8fcc29f1f1f@d34g2000vbm.googlegroups.com>

On Sep 23, 1:52=A0am, Bart Lateur <bart.lat...@pandora.be> wrote:
> pgodfrin wrote:
> >(what are XS modules?)
>
> Modules that are implemented as a DLL, with a bootstrap/interface layer
> in Perl.
>
> "XS" (pronounced excess; yes, it's a pun) is system of macros to write
> the C interface to Perl portably.
>
> --
> =A0 =A0 =A0 =A0 Bart.

kewl...thanx!
pg


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

Date: Wed, 23 Sep 2009 11:24:33 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: Active State 64-bit and Win32 Modules
Message-Id: <h9dejt$5d8$1@news.eternal-september.org>

Bart Lateur wrote:
> pgodfrin wrote:
> 
>> (what are XS modules?)
> 
> Modules that are implemented as a DLL, with a bootstrap/interface layer
> in Perl.
> 
> "XS" (pronounced excess; yes, it's a pun) is system of macros to write
> the C interface to Perl portably.
> 

When I'm behind one of those giant BMW SUVs I note that the "X5"
looks like "XS".


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

Date: Wed, 23 Sep 2009 18:24:23 -0700 (PDT)
From: Douglas Wilson <douglasg.wilson@gmail.com>
Subject: Re: Button in WWW::Mechanize
Message-Id: <3b028b7d-e8c4-4720-81a3-e72c9b40caba@o13g2000vbl.googlegroups.com>

On Sep 20, 8:02=A0am, "John" <john1...@yahoo.com> wrote:

> $agent->click('This One');
> print $agent->$content();

Typo just here or in your program. Should be:
print $agent->content();


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

Date: Wed, 23 Sep 2009 19:21:08 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: decimal round off issue
Message-Id: <slrnhbkm86.okr.hjp-usenet2@hrunkner.hjp.at>

On 2009-09-22 17:34, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Shiping Zhang <spz1st@gmail.com> wrote:
>>Is this a bug in perl?
>>
>>$v = sprintf "%.1f", 2.25;
>>print $v, "\n";
>>
>>The above code produced 2.2
>
> I cannot reproduce this observation. For me it prints 2.3.
> ( v5.10.0 built for MSWin32-x86-multi-thread)

Strange. It should produce 2.2 (2.25 is exactly halfway between 2.2 and
2.3, so the "round to even" rule is used). However, 2.2 and 2.3 aren't
exactly representable, so maybe that's where the rounding error is.

On Debian Linux (perl, v5.10.0 built for i486-linux-gnu-thread-multi),
this:

perl -e 'for(2.15,2.25,2.35,2.45,2.55,2.65, 2.75, 2.85, 2.95) {printf "%.60f %.1f\n", $_, $_ }'

prints:

2.149999999999999911182158029987476766109466552734375000000000 2.1
2.250000000000000000000000000000000000000000000000000000000000 2.2
2.350000000000000088817841970012523233890533447265625000000000 2.4
2.450000000000000177635683940025046467781066894531250000000000 2.5
2.549999999999999822364316059974953532218933105468750000000000 2.5
2.649999999999999911182158029987476766109466552734375000000000 2.6
2.750000000000000000000000000000000000000000000000000000000000 2.8
2.850000000000000088817841970012523233890533447265625000000000 2.9
2.950000000000000177635683940025046467781066894531250000000000 3.0

which is exactly correct: The values which are slightly above or below
0.x5 are rounded up or down as appropriate, and 2.25 and 2.75 are
rounded to even.

	hp



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

Date: Wed, 23 Sep 2009 12:21:39 -0700
From: sln@netherlands.com
Subject: Re: decimal round off issue
Message-Id: <jqpkb5lr16mne0lj6amurmmltci059h4m5@4ax.com>

On Wed, 23 Sep 2009 19:21:08 +0200, "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:

>On 2009-09-22 17:34, Jürgen Exner <jurgenex@hotmail.com> wrote:
>> Shiping Zhang <spz1st@gmail.com> wrote:
>>>Is this a bug in perl?
>>>
>>>$v = sprintf "%.1f", 2.25;
>>>print $v, "\n";
>>>
>>>The above code produced 2.2
>>
>> I cannot reproduce this observation. For me it prints 2.3.
>> ( v5.10.0 built for MSWin32-x86-multi-thread)
>
>Strange. It should produce 2.2 (2.25 is exactly halfway between 2.2 and
>2.3, so the "round to even" rule is used). However, 2.2 and 2.3 aren't
>exactly representable, so maybe that's where the rounding error is.
>
>On Debian Linux (perl, v5.10.0 built for i486-linux-gnu-thread-multi),
>this:
>
>perl -e 'for(2.15,2.25,2.35,2.45,2.55,2.65, 2.75, 2.85, 2.95) {printf "%.60f %.1f\n", $_, $_ }'
>
>prints:
>
>2.149999999999999911182158029987476766109466552734375000000000 2.1
>2.250000000000000000000000000000000000000000000000000000000000 2.2
>2.350000000000000088817841970012523233890533447265625000000000 2.4
>2.450000000000000177635683940025046467781066894531250000000000 2.5
>2.549999999999999822364316059974953532218933105468750000000000 2.5
>2.649999999999999911182158029987476766109466552734375000000000 2.6
>2.750000000000000000000000000000000000000000000000000000000000 2.8
>2.850000000000000088817841970012523233890533447265625000000000 2.9
>2.950000000000000177635683940025046467781066894531250000000000 3.0
>
>which is exactly correct: The values which are slightly above or below
>0.x5 are rounded up or down as appropriate, and 2.25 and 2.75 are
>rounded to even.
>
>	hp

I never heard of that "round to even" rule. On my build it rounds "up"
all the time. Maybe I don't have the latest build.

perl -e "for(2.15,2.25,2.35,2.45,2.55,2.65, 2.75, 2.85, 2.95) {printf \"%.60f %.1f\n\", $_, $_ }"

2.149999999999999900000000000000000000000000000000000000000000 2.1
2.250000000000000000000000000000000000000000000000000000000000 2.3
2.350000000000000100000000000000000000000000000000000000000000 2.4
2.450000000000000200000000000000000000000000000000000000000000 2.5
2.549999999999999800000000000000000000000000000000000000000000 2.5
2.649999999999999900000000000000000000000000000000000000000000 2.6
2.750000000000000000000000000000000000000000000000000000000000 2.8
2.850000000000000100000000000000000000000000000000000000000000 2.9
2.950000000000000200000000000000000000000000000000000000000000 3.0

I'm sure this is a result of a define flag passed via compiler option.
I' got the active state 5.10 built using gcc. I looked over the build
parameters using perl -V. I've only used MS compilers, so I don't know
some of the options listed. I looked for optimizations that I recognized,
only saw O2, compile for speed. MS has some /FP: optimizations like
precise/strict,etc.., that gcc doesen't.
Gcc looks like it has nvtype as double, its size 64 bit.
----------------
v5.10.0 built for MSWin32-x86-multi-thread
(with 5 registered patches)

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

-sln


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

Date: Wed, 23 Sep 2009 22:51:36 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: decimal round off issue
Message-Id: <slrnhbl2ir.jb.hjp-usenet2@hrunkner.hjp.at>

On 2009-09-23 19:21, sln@netherlands.com <sln@netherlands.com> wrote:
> On Wed, 23 Sep 2009 19:21:08 +0200, "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>>On 2009-09-22 17:34, Jürgen Exner <jurgenex@hotmail.com> wrote:
>>> Shiping Zhang <spz1st@gmail.com> wrote:
>>>>Is this a bug in perl?
>>>>
>>>>$v = sprintf "%.1f", 2.25;
>>>>print $v, "\n";
>>>>
>>>>The above code produced 2.2
>>>
>>> I cannot reproduce this observation. For me it prints 2.3.
>>> ( v5.10.0 built for MSWin32-x86-multi-thread)
>>
>>Strange. It should produce 2.2 (2.25 is exactly halfway between 2.2 and
>>2.3, so the "round to even" rule is used). However, 2.2 and 2.3 aren't
>>exactly representable, so maybe that's where the rounding error is.
>>
>>On Debian Linux (perl, v5.10.0 built for i486-linux-gnu-thread-multi),
>>this:
>>
>>perl -e 'for(2.15,2.25,2.35,2.45,2.55,2.65, 2.75, 2.85, 2.95) {printf "%.60f %.1f\n", $_, $_ }'
>>
>>prints:
>>
>>2.149999999999999911182158029987476766109466552734375000000000 2.1
>>2.250000000000000000000000000000000000000000000000000000000000 2.2
>>2.350000000000000088817841970012523233890533447265625000000000 2.4
>>2.450000000000000177635683940025046467781066894531250000000000 2.5
>>2.549999999999999822364316059974953532218933105468750000000000 2.5
>>2.649999999999999911182158029987476766109466552734375000000000 2.6
>>2.750000000000000000000000000000000000000000000000000000000000 2.8
>>2.850000000000000088817841970012523233890533447265625000000000 2.9
>>2.950000000000000177635683940025046467781066894531250000000000 3.0
>>
>>which is exactly correct: The values which are slightly above or below
>>0.x5 are rounded up or down as appropriate, and 2.25 and 2.75 are
>>rounded to even.
>
> I never heard of that "round to even" rule.

It is mentioned in this group just about every time that rounding is
discussed, which is probably at least once or twice per year.

The rule was used at least since the early 20th century (Wikipedia cites
a book from 1906). In IEEE-754 arithmetic (which is used in all current
FP units) it is the default rounding mode.

> On my build it rounds "up"
> all the time. Maybe I don't have the latest build.
>
> perl -e "for(2.15,2.25,2.35,2.45,2.55,2.65, 2.75, 2.85, 2.95) {printf \"%.60f %.1f\n\", $_, $_ }"
>
> 2.149999999999999900000000000000000000000000000000000000000000 2.1
> 2.250000000000000000000000000000000000000000000000000000000000 2.3
> 2.350000000000000100000000000000000000000000000000000000000000 2.4
> 2.450000000000000200000000000000000000000000000000000000000000 2.5
> 2.549999999999999800000000000000000000000000000000000000000000 2.5
> 2.649999999999999900000000000000000000000000000000000000000000 2.6
> 2.750000000000000000000000000000000000000000000000000000000000 2.8
> 2.850000000000000100000000000000000000000000000000000000000000 2.9
> 2.950000000000000200000000000000000000000000000000000000000000 3.0
>
> I'm sure this is a result of a define flag passed via compiler option.

More likely it's caused by the implementation of sprintf in the C
library.

> I' got the active state 5.10 built using gcc. I looked over the build
> parameters using perl -V.

Is there a "standard" C library on Windows which gcc has to use or does
it use the glibc? I suspect it's the former (I've seen similar results
with Microsofts C compiler).

	hp


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

Date: Thu, 24 Sep 2009 02:10:05 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: decimal round off issue
Message-Id: <dgtqo6-2892.ln1@osiris.mauzo.dyndns.org>


Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> 
> Is there a "standard" C library on Windows which gcc has to use or does
> it use the glibc? I suspect it's the former (I've seen similar results
> with Microsofts C compiler).

Huh? glibc is Linux- (well, and Hurd-) only. gcc on Win32 uses
MSVCRT.DLL, which used to be part of MSVC6 and nowadays is part of
Windows, or Internet Explorer, or something. Later versions of MSVC
insist on using their own versions of the C library, which cause
Interesting problems if you have a DLL compiled against one loaded into
an EXE compiled against another. (This is one reason why it's
particularly important to compile modules with the correct compiler on
Win32.)

Ben



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

Date: Thu, 24 Sep 2009 01:32:35 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: decimal round off issue
Message-Id: <slrnhblj1j.amb.nospam-abuse@chorin.math.berkeley.edu>

On 2009-09-24, Ben Morrow <ben@morrow.me.uk> wrote:
> Huh? glibc is Linux- (well, and Hurd-) only.

Last time I compiled glibc was several years ago.  But it was nowhere
close to Linux and/or Hurd.  It is just a C library on top of POSIX -
at lest at was at the time...

> gcc on Win32 uses MSVCRT.DLL,

AFAIK, there are many gcc's on Win32, all (?) using different CRTL...

Yours,
Ilya


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

Date: Wed, 23 Sep 2009 18:58:39 -0700
From: sln@netherlands.com
Subject: Re: decimal round off issue
Message-Id: <9bhlb5dq47mcahfbfhivipj5dh20m2g7fo@4ax.com>

On Wed, 23 Sep 2009 22:51:36 +0200, "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:

>On 2009-09-23 19:21, sln@netherlands.com <sln@netherlands.com> wrote:
>> On Wed, 23 Sep 2009 19:21:08 +0200, "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>>>On 2009-09-22 17:34, Jürgen Exner <jurgenex@hotmail.com> wrote:
>>>> Shiping Zhang <spz1st@gmail.com> wrote:
<snip>
>> I never heard of that "round to even" rule.
>
>It is mentioned in this group just about every time that rounding is
>discussed, which is probably at least once or twice per year.
>
>The rule was used at least since the early 20th century (Wikipedia cites
>a book from 1906). In IEEE-754 arithmetic (which is used in all current
>FP units) it is the default rounding mode.
>
Yeah I just read that on wikipedia. I imagine that a fpu has
at least 2, 80 bit registers to do comarisons, +-/* operations,
and result (don't know about this at all).
When the fraction is to be chopped to 64 bit variable, the lsb
is set to 0, if the lsb-1 bit in the register is set, not sure.
It says 'midway'.
I don't thinks this is a fp rounding issue, since by the standard,
this would be consistent across fp hardware.

>> On my build it rounds "up"
>> all the time. Maybe I don't have the latest build.
>> I'm sure this is a result of a define flag passed via compiler option.
>
>More likely it's caused by the implementation of sprintf in the C
>library.
>
I think you are right on it being a lib implementation issue.

>> I' got the active state 5.10 built using gcc. I looked over the build
>> parameters using perl -V.
>
>Is there a "standard" C library on Windows which gcc has to use or does
>it use the glibc? I suspect it's the former (I've seen similar results
>with Microsofts C compiler).
>
>	hp

There is a standard set of dll's that comes with Windows os',
2004 seems to be the last year that CRT was modified (added to).
Some older programs used to just include some runtime libs (dll's) in thier
exe path.

Microsoft defines 'core' dll's (crt, win32 interface, etc..) in thier os,
that get put in the system32 dir, part of the system path.

Most programs that link to them use import .lib 's.
That was seen all over gcc. Most can just get the platform sdk and
grab the lib's. Header files are a whole different nightmare.

So, yes. Gcc links with msvcrt.lib (import) which loads the system
dll when it runs. Single threaded static libc is no longer available
since VC2002/3/5/...

But gcc uses /MD multithread-dynamic CRT library option. So thats
where it is.

In all of MS compilers, there is the option to compile as either
C or C++. It looks like Gcc compiles it as C.
I have VC-2005.

Still, you have to wonder why MS, who supposedly is ANSI CRT
would differ from other compilers in its sprintf results.
I thought it could be that gcc doesn't use perhaps an optimization
that MS uses in its comiler that may pertain to floating point.

On the other hand, there is alot of defines being passed to the
Perl source. Are you sure that sprintf/printf from the CRT is
is not being bypassed via custom Perl implementation?

Either way, it might be nice to compile it under vc-2005,
using the float option /FP:precision

-sln

---<cut>-------
c:\temp>perl -V

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -
DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IM
PLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='12.0.8804', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksi
ze=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"C:
\Perl\lib\CORE"  -machine:x86'
    libpth=\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32
 .lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib ws2_
32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comd
lg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib
ws2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf  -
libpath:"C:\Perl\lib\CORE"  -machine:x86'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
                        PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
                        PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_ITHREADS
                        USE_LARGE_FILES USE_PERLIO USE_SITECUSTOMIZE
  Locally applied patches:
        ActivePerl Build 1004 [287188]
        33741 avoids segfaults invoking S_raise_signal() (on Linux)
        33763 Win32 process ids can have more than 16 bits
        32809 Load 'loadable object' with non-default file extension
        32728 64-bit fix for Time::Local
  Built under MSWin32
  Compiled at Sep  3 2008 13:16:37
  @INC:
    C:/Perl/site/lib
    C:/Perl/lib
    .

c:\temp>





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

Date: Wed, 23 Sep 2009 19:11:42 -0700
From: sln@netherlands.com
Subject: Re: decimal round off issue
Message-Id: <89llb55b14un4s6mca7p9tv8ililegrb6r@4ax.com>

On Wed, 23 Sep 2009 18:58:39 -0700, sln@netherlands.com wrote:

>---<cut>-------

c:\temp>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

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.


c:\temp>

>c:\temp>perl -V
>
>Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
>  Platform:
>    osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
>    uname=''
>    config_args='undef'
>    hint=recommended, useposix=true, d_sigaction=undef
>    useithreads=define, usemultiplicity=define
>    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
>    use64bitint=undef, use64bitall=undef, uselongdouble=undef
>    usemymalloc=n, bincompat5005=undef
>  Compiler:
>    cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -
>DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IM
>PLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
>    optimize='-MD -Zi -DNDEBUG -O1',
>    cppflags='-DWIN32'
>    ccversion='12.0.8804', gccversion='', gccosandvers=''
>    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
>    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
>    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksi
>ze=8
>    alignbytes=8, prototype=define
>  Linker and Libraries:
>    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"C:
>\Perl\lib\CORE"  -machine:x86'
>    libpth=\lib
>    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32
>.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib ws2_
>32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
>    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comd
>lg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib
>ws2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
>    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib
>    gnulibc_version=''
>  Dynamic Linking:
>    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
>    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf  -
>libpath:"C:\Perl\lib\CORE"  -machine:x86'
>
>
>Characteristics of this binary (from libperl):
>  Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
>                        PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
>                        PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_ITHREADS
>                        USE_LARGE_FILES USE_PERLIO USE_SITECUSTOMIZE
>  Locally applied patches:
>        ActivePerl Build 1004 [287188]
>        33741 avoids segfaults invoking S_raise_signal() (on Linux)
>        33763 Win32 process ids can have more than 16 bits
>        32809 Load 'loadable object' with non-default file extension
>        32728 64-bit fix for Time::Local
>  Built under MSWin32
>  Compiled at Sep  3 2008 13:16:37
>  @INC:
>    C:/Perl/site/lib
>    C:/Perl/lib
>    .
>
>c:\temp>
>
>



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

Date: Thu, 24 Sep 2009 09:08:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: decimal round off issue
Message-Id: <40mro6-j2d2.ln1@osiris.mauzo.dyndns.org>


Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2009-09-24, Ben Morrow <ben@morrow.me.uk> wrote:
> > Huh? glibc is Linux- (well, and Hurd-) only.
> 
> Last time I compiled glibc was several years ago.  But it was nowhere
> close to Linux and/or Hurd.  It is just a C library on top of POSIX -
> at lest at was at the time...

http://www.gnu.org/software/libc/ports.html

    Version 2 currently supports only GNU systems (both Hurd-based and
    Linux-based).

> > gcc on Win32 uses MSVCRT.DLL,
> 
> AFAIK, there are many gcc's on Win32, all (?) using different CRTL...

Really? The only port I've ever seen is the MinGW port, which uses
MSVCRT as it's libc. (I don't count Cygwin/Interix/whatever gccs as
running on Win32, and neither does perl.)

Ben



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

Date: Thu, 24 Sep 2009 04:00:04 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 5.29 How can I read in a file by paragraphs?
Message-Id: <89Cum.12089$tG1.4108@newsfe22.iad>

This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to 
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

5.29: How can I read in a file by paragraphs?

    Use the $/ variable (see perlvar for details). You can either set it to
    "" to eliminate empty paragraphs ("abc\n\n\n\ndef", for instance, gets
    treated as two paragraphs and not three), or "\n\n" to accept empty
    paragraphs.

    Note that a blank line must have no blanks in it. Thus
    "fred\n \nstuff\n\n" is one paragraph, but "fred\n\nstuff\n\n" is two.



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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in 
perlfaq.pod.


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

Date: Wed, 23 Sep 2009 16:00:02 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 7.13 What's a closure?
Message-Id: <6Crum.234922$vp.124541@newsfe12.iad>

This is an excerpt from the latest version perlfaq7.pod, which
comes with the standard Perl distribution. These postings aim to 
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

7.13: What's a closure?

    Closures are documented in perlref.

    *Closure* is a computer science term with a precise but hard-to-explain
    meaning. Usually, closures are implemented in Perl as anonymous
    subroutines with lasting references to lexical variables outside their
    own scopes. These lexicals magically refer to the variables that were
    around when the subroutine was defined (deep binding).

    Closures are most often used in programming languages where you can have
    the return value of a function be itself a function, as you can in Perl.
    Note that some languages provide anonymous functions but are not capable
    of providing proper closures: the Python language, for example. For more
    information on closures, check out any textbook on functional
    programming. Scheme is a language that not only supports but encourages
    closures.

    Here's a classic non-closure function-generating function:

            sub add_function_generator {
                    return sub { shift() + shift() };
                    }

            $add_sub = add_function_generator();
            $sum = $add_sub->(4,5);                # $sum is 9 now.

    The anonymous subroutine returned by add_function_generator() isn't
    technically a closure because it refers to no lexicals outside its own
    scope. Using a closure gives you a *function template* with some
    customization slots left out to be filled later.

    Contrast this with the following make_adder() function, in which the
    returned anonymous function contains a reference to a lexical variable
    outside the scope of that function itself. Such a reference requires
    that Perl return a proper closure, thus locking in for all time the
    value that the lexical had when the function was created.

            sub make_adder {
                    my $addpiece = shift;
                    return sub { shift() + $addpiece };
            }

            $f1 = make_adder(20);
            $f2 = make_adder(555);

    Now "&$f1($n)" is always 20 plus whatever $n you pass in, whereas
    "&$f2($n)" is always 555 plus whatever $n you pass in. The $addpiece in
    the closure sticks around.

    Closures are often used for less esoteric purposes. For example, when
    you want to pass in a bit of code into a function:

            my $line;
            timeout( 30, sub { $line = <STDIN> } );

    If the code to execute had been passed in as a string, '$line =
    <STDIN>', there would have been no way for the hypothetical timeout()
    function to access the lexical variable $line back in its caller's
    scope.

    Another use for a closure is to make a variable *private* to a named
    subroutine, e.g. a counter that gets initialized at creation time of the
    sub and can only be modified from within the sub. This is sometimes used
    with a BEGIN block in package files to make sure a variable doesn't get
    meddled with during the lifetime of the package:

            BEGIN {
                    my $id = 0;
                    sub next_id { ++$id }
            }

    This is discussed in more detail in perlsub, see the entry on
    *Persistent Private Variables*.



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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in 
perlfaq.pod.


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

Date: Wed, 23 Sep 2009 10:00:02 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 7.2 What are all these $@%&* punctuation signs, and how do I know when to use them?
Message-Id: <Ckmum.441940$Ta5.261770@newsfe15.iad>

This is an excerpt from the latest version perlfaq7.pod, which
comes with the standard Perl distribution. These postings aim to 
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

7.2: What are all these $@%&* punctuation signs, and how do I know when to use them?

    They are type specifiers, as detailed in perldata:

            $ for scalar values (number, string or reference)
            @ for arrays
            % for hashes (associative arrays)
            & for subroutines (aka functions, procedures, methods)
            * for all types of that symbol name.  In version 4 you used them like
              pointers, but in modern perls you can just use references.

    There are couple of other symbols that you're likely to encounter that
    aren't really type specifiers:

            <> are used for inputting a record from a filehandle.
            \  takes a reference to something.

    Note that <FILE> is *neither* the type specifier for files nor the name
    of the handle. It is the "<>" operator applied to the handle FILE. It
    reads one line (well, record--see "$/" in perlvar) from the handle FILE
    in scalar context, or *all* lines in list context. When performing open,
    close, or any other operation besides "<>" on files, or even when
    talking about the handle, do *not* use the brackets. These are correct:
    "eof(FH)", "seek(FH, 0, 2)" and "copying from STDIN to FILE".



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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in 
perlfaq.pod.


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

Date: Thu, 24 Sep 2009 10:00:01 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 7.23 How do I create a switch or case statement?
Message-Id: <BqHum.19879$944.19430@newsfe09.iad>

This is an excerpt from the latest version perlfaq7.pod, which
comes with the standard Perl distribution. These postings aim to 
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

7.23: How do I create a switch or case statement?

    In Perl 5.10, use the "given-when" construct described in perlsyn:

            use 5.010;

            given ( $string ) {
                    when( 'Fred' )        { say "I found Fred!" }
                    when( 'Barney' )      { say "I found Barney!" }
                    when( /Bamm-?Bamm/ )  { say "I found Bamm-Bamm!" }
                    default               { say "I don't recognize the name!" }
                    };

    If one wants to use pure Perl and to be compatible with Perl versions
    prior to 5.10, the general answer is to use "if-elsif-else":

            for ($variable_to_test) {
                    if    (/pat1/)  { }     # do something
                    elsif (/pat2/)  { }     # do something else
                    elsif (/pat3/)  { }     # do something else
                    else            { }     # default
                    }

    Here's a simple example of a switch based on pattern matching, lined up
    in a way to make it look more like a switch statement. We'll do a
    multiway conditional based on the type of reference stored in
    $whatchamacallit:

        SWITCH: for (ref $whatchamacallit) {

            /^$/            && die "not a reference";

            /SCALAR/        && do {
                                    print_scalar($$ref);
                                    last SWITCH;
                            };

            /ARRAY/         && do {
                                    print_array(@$ref);
                                    last SWITCH;
                            };

            /HASH/          && do {
                                    print_hash(%$ref);
                                    last SWITCH;
                            };

            /CODE/          && do {
                                    warn "can't print function ref";
                                    last SWITCH;
                            };

            # DEFAULT

            warn "User defined type skipped";

        }

    See perlsyn for other examples in this style.

    Sometimes you should change the positions of the constant and the
    variable. For example, let's say you wanted to test which of many
    answers you were given, but in a case-insensitive way that also allows
    abbreviations. You can use the following technique if the strings all
    start with different characters or if you want to arrange the matches so
    that one takes precedence over another, as "SEND" has precedence over
    "STOP" here:

            chomp($answer = <>);
            if    ("SEND"  =~ /^\Q$answer/i) { print "Action is send\n"  }
            elsif ("STOP"  =~ /^\Q$answer/i) { print "Action is stop\n"  }
            elsif ("ABORT" =~ /^\Q$answer/i) { print "Action is abort\n" }
            elsif ("LIST"  =~ /^\Q$answer/i) { print "Action is list\n"  }
            elsif ("EDIT"  =~ /^\Q$answer/i) { print "Action is edit\n"  }

    A totally different approach is to create a hash of function references.

            my %commands = (
                    "happy" => \&joy,
                    "sad",  => \&sullen,
                    "done"  => sub { die "See ya!" },
                    "mad"   => \&angry,
            );

            print "How are you? ";
            chomp($string = <STDIN>);
            if ($commands{$string}) {
                    $commands{$string}->();
            } else {
                    print "No such command: $string\n";
            }

    Starting from Perl 5.8, a source filter module, "Switch", can also be
    used to get switch and case. Its use is now discouraged, because it's
    not fully compatible with the native switch of Perl 5.10, and because,
    as it's implemented as a source filter, it doesn't always work as
    intended when complex syntax is involved.



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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in 
perlfaq.pod.


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

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


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