[29992] in Perl-Users-Digest
Perl-Users Digest, Issue: 1235 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 26 14:09:42 2008
Date: Sat, 26 Jan 2008 11:09:06 -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 Sat, 26 Jan 2008 Volume: 11 Number: 1235
Today's topics:
fault on add cart page Tami@des.com
Re: fault on add cart page <jurgenex@hotmail.com>
Re: fault on add cart page <ben@morrow.me.uk>
Re: fault on add cart page Tami@des.com
Re: File::SortedSeek not working <tzhai2007@gmail.com>
new CPAN modules on Sat Jan 26 2008 (Randal Schwartz)
Re: non nntp usenet <invalid@invalid.net>
Re: regular expression negate a word (not character) <Summercoolness@gmail.com>
Re: regular expression negate a word (not character) bearophileHUGS@lycos.com
Re: regular expression negate a word (not character) <paddy3118@googlemail.com>
Re: regular expression negate a word (not character) bearophileHUGS@lycos.com
Re: sprintf rouding error <joe@inwap.com>
Re: sprintf rouding error <bart.lateur@pandora.be>
Re: sprintf rouding error <invalid@invalid.net>
Re: sprintf rouding error <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 26 Jan 2008 16:17:28 GMT
From: Tami@des.com
Subject: fault on add cart page
Message-Id: <b6nmp3tfdfpebo08da6snl0mktl1vvr4o2@4ax.com>
Hi
I have a problem that I cannot find
The site has been working all ok BUT all of a sudden a fault has come up
I have a page ( shopping cart page ) where I can select things then
goto the bottom of the page and press a button ( ADD TO CART ) which
then should go to a cgi script and run it BUT for some reason when you
press the add button it brings the name of the script up and ask if you
want to safe the cgi script.
Any help would be most welcome
Tami
------------------------------
Date: Sat, 26 Jan 2008 16:31:36 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: fault on add cart page
Message-Id: <mtnmp3tmmbl8t28mg304ue0ms6pj2fdbtj@4ax.com>
Tami@des.com wrote:
>I have a problem that I cannot find
I have a problem, too, but it is easy to find: what does your problem have
to do with Perl?
jue
------------------------------
Date: Sat, 26 Jan 2008 16:22:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: fault on add cart page
Message-Id: <eb3s65-jlo.ln1@osiris.mauzo.dyndns.org>
Quoth Tami@des.com:
>
> I have a page ( shopping cart page ) where I can select things then
> goto the bottom of the page and press a button ( ADD TO CART ) which
> then should go to a cgi script and run it BUT for some reason when you
> press the add button it brings the name of the script up and ask if you
> want to safe the cgi script.
You have a server configuration problem. Your server is not running the
CGI script, but instead is serving it back to the browser as-is. If you
are using Apache, you may need to move the script to a cgi-bin directory
or turn on Options ExecCGI; otherwise, or if this doesn't help, you will
need to ask in a group relevant to your web server.
Ben
------------------------------
Date: Sat, 26 Jan 2008 17:55:14 GMT
From: Tami@des.com
Subject: Re: fault on add cart page
Message-Id: <5osmp31q3uifb4obl8ib20kpvt3b1q9vq4@4ax.com>
On Sat, 26 Jan 2008 16:22:38 +0000, Ben Morrow <ben@morrow.me.uk> wrote:
>
>Quoth Tami@des.com:
>>
>> I have a page ( shopping cart page ) where I can select things then
>> goto the bottom of the page and press a button ( ADD TO CART ) which
>> then should go to a cgi script and run it BUT for some reason when you
>> press the add button it brings the name of the script up and ask if you
>> want to safe the cgi script.
>
>You have a server configuration problem. Your server is not running the
>CGI script, but instead is serving it back to the browser as-is. If you
>are using Apache, you may need to move the script to a cgi-bin directory
>or turn on Options ExecCGI; otherwise, or if this doesn't help, you will
>need to ask in a group relevant to your web server.
>
>Ben
Hi Ben
Thank you for getting back to me.
I thought it might be that BUT I ran a test script and it works fine.
The script is in the right directory as it all worked before this fault
started
Running Apache
Tami
------------------------------
Date: Sat, 26 Jan 2008 10:05:21 -0800 (PST)
From: worker <tzhai2007@gmail.com>
Subject: Re: File::SortedSeek not working
Message-Id: <036ecbcf-46fe-438e-8364-742d45c02e02@t1g2000pra.googlegroups.com>
On Jan 24, 11:24 pm, worker <tzhai2...@gmail.com> wrote:
> On Jan 24, 4:00 pm, xhos...@gmail.com wrote:
>
>
>
> > worker <tzhai2...@gmail.com> wrote:
> > > On Jan 24, 12:36 pm, "J. Gleixner" <glex_no-s...@qwest-spam-
> > > no.invalid> wrote:
> > > > worker wrote:
> > > > > Hi, all,
> > > > > I am using this File::SortedSeek module to search a big data file
> > > > > and it is not working.
>
> > > > > The data file has these entries:
>
> > > > > 01/01/1960,0.75
> > > > > 01/02/1960,0.00
>
> > The example code produced file like this:
>
> > 01/10/1949,0.1
> > 01/02/1950,0.2
> > 1/1/1960,7.0
> > 1/2/1960,8.0
> > 3/3/1980,9.0
>
> > It is not canonical, as the sometimes it is zero-padded and sometimes
> > it is not. It does appear to be in a reasonable sorted order, but I
> > don't know if that is by design or by accident (If you designed something
> > to sort it properly, why doesn't it canonicalize it while it is at it?)
>
> > But isn't clear if the semantics are day/month/year or month/day/year,
> > as both are compatible with the given order. I'm assuming day/month/year
>
> > ...
>
> > > $line = <DTEST>;
> > > chomp ($line);
> > > $tell = File::SortedSeek::alphabetic(*TEST,$line,\&munge_string);
>
> > The query $line needs to be munged in way compatible with the querent
> > lines' munging. Otherwise it won't work. The easiest way to do this is to
> > pass in munge_string($line) rather than $line.
>
> > > sub munge_string {
> > > my $line = shift || return undef;
> > > # return ($line =~ m/\|(\w+)$/) ? $1 : undef;
> > > # return ($line =~ m/^[0-9]+\/[0-9]+\/[0-9]+,/) ? $1 : undef;
> > > return ($line =~ m/^\/,/) ? $1 : undef;
> > > }
>
> > The function has to munge the data in such a way that the lines of the
> > file being searched are in alphabetic sorted order after the munging. With
> > the sort order your file already has, it thus has to reorder the fields so
> > that the most significant (year) comes first.
>
> > return ($line =~ m/(^[0-9]+)\/([0-9]+)\/([0-9]+)(,|$)/) ?
> > sprintf "%04d%02d%02d", $3,$2,$1 : undef;
>
> > The (,|$) is so that it will work on the query, which is not followed by a
> > comma, as well as the querent.
>
> > Xho
>
> > --
> > --------------------http://NewsReader.Com/--------------------
> > The costs of publication of this article were defrayed in part by the
> > payment of page charges. This article must therefore be hereby marked
> > advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
> > this fact.
>
> thnx for the explanation.
> I made the following changes according to your suggestions:
>
> $aSimDateMunged = &munge_string($aSimDate);
> $tell = File::SortedSeek::alphabetic(*FRAW,$aSimDateMunged,
> \&munge_string);
>
> return ($line =~ m/(^[0-9]+)\/([0-9]+)\/([0-9]+)(,|$)/) ?
> sprintf "%04d%02d%02d", $3,$1,$2 : undef;
>
> my data is in month/day/year.
>
> once I tried it, this is what I got as response:
>
> Name "main::tell" used only once: possible typo at ztest.pl line 22.
>
> Ark, File::SortedSeek got to EOF
> Failed to find: 'SCALAR(0x354c0)'
> The search mode for the file was 'Ascending order'
> $line: undef
> $next: undef
> File size: 74 Bytes
> $top: 55 Bytes
> $bottom: 74 Bytes
> Perhaps try reversing the search mode
> Are you using the correct method - alhpabetic or numeric?
>
> If you think it is a bug please send a bug report to:
> jfree...@tassie.net.au
> A sample of the file, the call to this module and
> this error message will help to fix the problem
> Use of uninitialized value in concatenation (.) or string at ztest.pl
> line 25, <
> TEST> line 8.
> Found it?::
>
> Help?
Hello?
could anyone help with this? thx.
------------------------------
Date: Sat, 26 Jan 2008 05:42:19 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sat Jan 26 2008
Message-Id: <Jv8L6J.526@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Asterisk-config-0.91
http://search.cpan.org/~hoowa/Asterisk-config-0.91/
the Asterisk config read and write module.
----
CHI-0.04
http://search.cpan.org/~jswartz/CHI-0.04/
Unified cache interface
----
CPAN-Reporter-1.07_06
http://search.cpan.org/~dagolden/CPAN-Reporter-1.07_06/
Adds CPAN Testers reporting to CPAN.pm
----
Carp-Clan-Share-0.012
http://search.cpan.org/~rkrimen/Carp-Clan-Share-0.012/
Share your Carp::Clan settings with your whole Clan
----
Chart-OFC-0.05
http://search.cpan.org/~drolsky/Chart-OFC-0.05/
Generate data files for use with Open Flash Chart
----
Class-Data-Inheritable-0.07
http://search.cpan.org/~tmtm/Class-Data-Inheritable-0.07/
Inheritable, overridable class data
----
Class-Data-Inheritable-0.08
http://search.cpan.org/~tmtm/Class-Data-Inheritable-0.08/
Inheritable, overridable class data
----
Config-JSON-1.1.2
http://search.cpan.org/~rizen/Config-JSON-1.1.2/
A JSON based config file system.
----
Config-JSON-1.1.3
http://search.cpan.org/~rizen/Config-JSON-1.1.3/
A JSON based config file system.
----
Config-JSON-1.1.4
http://search.cpan.org/~rizen/Config-JSON-1.1.4/
A JSON based config file system.
----
Crypt-GCrypt-1.19
http://search.cpan.org/~aar/Crypt-GCrypt-1.19/
Perl interface to the GNU Cryptographic library
----
Crypt-GCrypt-1.20
http://search.cpan.org/~aar/Crypt-GCrypt-1.20/
Perl interface to the GNU Cryptographic library
----
Device-Davis-1.2.2
http://search.cpan.org/~stsander/Device-Davis-1.2.2/
Perl extension for communicating with Davis weather stations
----
Error-0.17012
http://search.cpan.org/~shlomif/Error-0.17012/
Error/exception handling in an OO-ish way
----
Finance-Bank-HSBC-1.05
http://search.cpan.org/~bisscuitt/Finance-Bank-HSBC-1.05/
Check your HSBC bank accounts from Perl
----
IO-Lambda-0.08
http://search.cpan.org/~karasik/IO-Lambda-0.08/
non-blocking I/O in lambda style
----
Language-Tea-0.03
http://search.cpan.org/~msilva/Language-Tea-0.03/
A Tea code converter.
----
Mail-IMAPClient-3.04
http://search.cpan.org/~markov/Mail-IMAPClient-3.04/
An IMAP Client API
----
Mail-SpamAssassin-Plugin-OpenPGP-1.0.3
http://search.cpan.org/~brondsem/Mail-SpamAssassin-Plugin-OpenPGP-1.0.3/
A SpamAssassin plugin that validates OpenPGP signed email.
----
Module-Find-0.06
http://search.cpan.org/~crenz/Module-Find-0.06/
Find and use installed modules in a (sub)category
----
MooseX-POE-0.06
http://search.cpan.org/~perigrin/MooseX-POE-0.06/
The Illicit Love Child of Moose and POE
----
Moxy-0.22
http://search.cpan.org/~tokuhirom/Moxy-0.22/
Mobile web development proxy
----
Pod-Extract-URI-0.3
http://search.cpan.org/~imalpass/Pod-Extract-URI-0.3/
Extract URIs from POD
----
Taint-Util-0.06
http://search.cpan.org/~avar/Taint-Util-0.06/
Test for and flip the taint flag without regex matches or eval
----
Text-Wrap-Smart-0.6
http://search.cpan.org/~schubiger/Text-Wrap-Smart-0.6/
Wrap text into chunks of (mostly) equal length
----
WWW-Bebo-API-0.0.03
http://search.cpan.org/~clscott/WWW-Bebo-API-0.0.03/
Bebo API implementation
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Fri, 25 Jan 2008 23:59:41 -0700
From: "Gerry Ford" <invalid@invalid.net>
Subject: Re: non nntp usenet
Message-Id: <1201330223_2319@sp12lax.superfeed.net>
"smallpond" <smallpond@juno.com> wrote in message
news:dd222dbd-3ece-4d65-adfd-e2b5de7195e4@s13g2000prd.googlegroups.com...
> On Jan 18, 4:27 am, "Regan Revised" <inva...@invalid.net> wrote:
>> How can Outlook Express pick up usenet messages that net::nntp can't?
>>
>> --
>>
>> Reagan Revision
>
>
> Extraordinary claims require extraordinary evidence.
> --S
To my mind, I'd already proved the point.
#!/usr/bin/perl -w
use strict;
use Net::NNTP ();
use constant NUMBER_OF_ARTICLES => 100;
use constant GROUP_NAME => 'comp.whatever';
use constant SERVER_NAME => 'newsgroups.comcast.net';
use constant NNTP_DEBUG => 0;
my $nntp = Net::NNTP->new(SERVER_NAME, 'Debug' => NNTP_DEBUG) or die;
my $USER = 'mpjensen7@comcast.net';
my $PASS = '';
$nntp->authinfo($USER,$PASS) or die $!;
my($article_count, $first_article, $last_article) = $nntp->group(GROUP_NAME)
or die;
# Which XOVER fields contain Subject: and From:?
my $count = 0;
my %xover_fmt = map( ($_, $count++), @{ $nntp->overview_fmt or die} );
die unless exists $xover_fmt{'Subject:'};
my $subject_offset = $xover_fmt{'Subject:'};
my $from_offset = $xover_fmt{'From:'};
my(@xover, $start_article);
RETRIEVE: while ($#xover+1 < NUMBER_OF_ARTICLES and $last_article >=
$first_article) {
# How many articles do we need? Stop retrieving if we have enough
my $articles_required = NUMBER_OF_ARTICLES - ($#xover+1) or last
RETRIEVE;
# Fetch overview information for the articles
$start_article = $last_article - ($articles_required-1);
$start_article = $start_article > $first_article ? $start_article :
$first_article;
my $xover_query = $start_article == $last_article ?
$start_article :
[$start_article, $last_article];
my $xover_ref = $nntp->xover($xover_query) or die;
# Store headers for the articles we've retrieved
foreach (sort {$b <=> $a} keys %$xover_ref) {
push @xover, $xover_ref->{$_};
}
} continue {
# Move the pointer forward to fetch previous articles
$last_article = $start_article - 1;
}
# Disconnect from the NNTP server
$nntp->quit;
print join("\n", map ($_->[$subject_offset].' from '.$_->[$from_offset],
@xover)),"\n";
#end source
My claim is that I've already shown that net::nntp can't find the mi5
persecution dude, Keith Thompson, or me. This goes out just shy of midnight
mountain time, about UTC neagtive six or so. If, within the day, you alter
the above script with appropriate parameters, e.g. changing the group, the
login, the password asnd the newsfeed, you can either "see" this message or
this precedes:
On Jan 24, 12:25 pm, xhos...@gmail.com wrote:
> I need a work queue, but I don't really care about the order (LIFO, FIFO,
> random) in which things come out of it. Either is pretty simple and
> efficient with a Perl array, and either would suffice. But I want the
> queue to not hold duplicate entries. I could use an array as a stack or
> queue, with a parallel hash to be checked to prevent duplicates from being
> entered. But why keep parallel data structures? Just use the hash as the
> queue:
>
> while (key %hash) {
> my $to_do=each %hash;
> delete $hash{$to_do};
> ## do stuff with $to_do, which might make new entries in %hash
>
> };
>
if "do stuff" might make entries in %hash, how do you guarantee you
won't be operating on a duplicate entry, since you delete
$hash{$to_do}?
#end quote
If someone can show that this article exists, using NNTP, it would be a
counter-example.
--
The most common of all follies is to believe passionately in the palpably
not true. It is the chief occupation of mankind.
-- H L Mencken, A Mencken Chrestomathy (1949)
------------------------------
Date: Sat, 26 Jan 2008 01:53:25 -0800 (PST)
From: Summercool <Summercoolness@gmail.com>
Subject: Re: regular expression negate a word (not character)
Message-Id: <7dea2f8e-66ba-48f7-9818-f1b6d41b4df9@n22g2000prh.googlegroups.com>
to add to the test cases, the regular expression must be able to grep
snowbird tire
tired on a snow day
snow tire and regular tire
------------------------------
Date: Sat, 26 Jan 2008 02:46:59 -0800 (PST)
From: bearophileHUGS@lycos.com
Subject: Re: regular expression negate a word (not character)
Message-Id: <5c5f4acd-02a7-4f6f-be34-d6814fb63e59@e23g2000prf.googlegroups.com>
Summercool:
> to add to the test cases, the regular expression must be able to grep
> snow tire and regular tire
I presume there only the second tire has to be found.
This is my first try:
text = """
tire
word tire word
word retire word
word tired word
snowbird tire word
tired on a snow day word
snow tire and regular tire word
word snow tire word
word snow tire word
word some snowtires word
"""
import re
def finder(text):
patt = re.compile( r"\b (\w*) \s* (tire)", re.VERBOSE)
for mo in patt.finditer(text):
if not mo.group(1).endswith("snow"):
yield mo.start(2)
for end in finder(text):
print end
The (lazy) output is the starting point of the "tire" that match:
1
11
28
43
63
73
120
Bye,
bearophile
------------------------------
Date: Sat, 26 Jan 2008 03:34:16 -0800 (PST)
From: Paddy <paddy3118@googlemail.com>
Subject: Re: regular expression negate a word (not character)
Message-Id: <c4176f34-4562-4bf7-a20c-ef364f2cbb10@q21g2000hsa.googlegroups.com>
On Jan 26, 1:16 am, Summercool <Summercooln...@gmail.com> wrote:
> somebody who is a regular expression guru... how do you negate a word
> and grep for all words that is
>
> tire
>
> but not
>
> snow tire
>
> or
>
> snowtire
>
> so for example, it will grep for
>
> winter tire
> tire
> retire
> tired
>
> but will not grep for
>
> snow tire
> snow tire
> some snowtires
>
> need to do it in one regular expression
Try the answer here:
http://mail.python.org/pipermail/tutor/2003-August/024902.html
------------------------------
Date: Sat, 26 Jan 2008 03:53:42 -0800 (PST)
From: bearophileHUGS@lycos.com
Subject: Re: regular expression negate a word (not character)
Message-Id: <89b30d74-4aad-4847-884b-8c784c13df48@c4g2000hsg.googlegroups.com>
Paddy:
> Try the answer here:
> http://mail.python.org/pipermail/tutor/2003-August/024902.html
But in the OP problem there can be variable-sized spaces in the
middle...
Bye,
bearophile
------------------------------
Date: Sat, 26 Jan 2008 00:45:55 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: sprintf rouding error
Message-Id: <UPSdnaIPnoKmbgfanZ2dnUVZ_t6onZ2d@comcast.com>
Broki@gmx.de wrote:
> What about the IEEE rounding and Perl...is it a fact that the
> "uncorrectness" with floating point conversion leads to the
> statistically interesting way to round 50% up/ 50% down?
No, it's because int($x+0.5) produces bad results when there
are many instances of $x = $n + 0.5 (for integer $n). Observe:
perl -le 'for $x (1.5, 2.5, 3.5, 4.5) {$sum1 += int($x+0.5); $sum2 += $x}; print "sum1=$sum1 sum2=$sum2"'
sum1=14 sum2=12
-Joe
------------------------------
Date: Sat, 26 Jan 2008 10:34:06 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: sprintf rouding error
Message-Id: <n72mp35gv4nvb8g1dbqdq7oa6olkabhvnp@4ax.com>
Joe Smith wrote:
>Broki@gmx.de wrote:
>
>> What about the IEEE rounding and Perl...is it a fact that the
>> "uncorrectness" with floating point conversion leads to the
>> statistically interesting way to round 50% up/ 50% down?
>
>No, it's because int($x+0.5) produces bad results when there
>are many instances of $x = $n + 0.5 (for integer $n). Observe:
>
>perl -le 'for $x (1.5, 2.5, 3.5, 4.5) {$sum1 += int($x+0.5); $sum2 += $x}; print "sum1=$sum1 sum2=$sum2"'
>sum1=14 sum2=12
What the heck are you talking about? int() truncates ("rounds towards
zero"), it doesn't round. The results you get are exact, not rounded
values.
0.5 is not a problem in floating point presentation, as 2 is a power of
2. So there is no error at all in any internal representation of $n+0.5,
for any integer $n (within reasonable limits).
Internally, a floating point value is represented as
+/-Sum(b(i) * 2**-i) * (2**e)
A summation over integer values of i , of a bit value b(i) that is
either 0 or 1, times 2 raised to the power of -i, for each i, the whole
possibly flipped in sign (mantissa), and multiplied by an signed integer
power of 2, e (exponent).
There are typically 53 bits in the mantissa, while e is limited to a
small signed integer.
This is actually a (possibly huge) integer divided by a power of 2.
So there's no problem at all representating, for example, the value of
(123 + 456/1024) as this is the same as (123*1024+456)/1024
And there definitely is not problem for 5.5 which is 11/2.
--
Bart.
------------------------------
Date: Sat, 26 Jan 2008 06:42:46 -0700
From: "Gerry Ford" <invalid@invalid.net>
Subject: Re: sprintf rouding error
Message-Id: <1201354408_2587@sp12lax.superfeed.net>
funny.
I never thought of this type of error as an answer to the subset problem,
but the bias seems to be in the rigth direction.
--
The most common of all follies is to believe passionately in the palpably
not true. It is the chief occupation of mankind.
-- H L Mencken, A Mencken Chrestomathy (1949)
"Joe Smith" <joe@inwap.com> wrote in message
news:UPSdnaIPnoKmbgfanZ2dnUVZ_t6onZ2d@comcast.com...
> Broki@gmx.de wrote:
>
>> What about the IEEE rounding and Perl...is it a fact that the
>> "uncorrectness" with floating point conversion leads to the
>> statistically interesting way to round 50% up/ 50% down?
>
> No, it's because int($x+0.5) produces bad results when there
> are many instances of $x = $n + 0.5 (for integer $n). Observe:
>
> perl -le 'for $x (1.5, 2.5, 3.5, 4.5) {$sum1 += int($x+0.5); $sum2 += $x};
> print "sum1=$sum1 sum2=$sum2"'
> sum1=14 sum2=12
>
> -Joe
------------------------------
Date: Sat, 26 Jan 2008 13:39:05 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: sprintf rouding error
Message-Id: <popr65-qlm.ln1@osiris.mauzo.dyndns.org>
Quoth Bart Lateur <bart.lateur@pandora.be>:
> Joe Smith wrote:
>
> >Broki@gmx.de wrote:
> >
> >> What about the IEEE rounding and Perl...is it a fact that the
> >> "uncorrectness" with floating point conversion leads to the
> >> statistically interesting way to round 50% up/ 50% down?
> >
> >No, it's because int($x+0.5) produces bad results when there
> >are many instances of $x = $n + 0.5 (for integer $n). Observe:
> >
> >perl -le 'for $x (1.5, 2.5, 3.5, 4.5) {$sum1 += int($x+0.5); $sum2 +=
> $x}; print "sum1=$sum1 sum2=$sum2"'
> >sum1=14 sum2=12
>
> What the heck are you talking about? int() truncates ("rounds towards
> zero"), it doesn't round. The results you get are exact, not rounded
> values.
Have you been following this thread at all? The OP was asking why 6274.5
(or some such) rounds to 6274, rather that to 6275 as he was taught in
school. Using int($x + 0.5) for rounding, rather than sprintf %.0f, will
give him what he wants; however, using values like this has
mathematically worrying properties, so it's not generally a good idea.
Ben
------------------------------
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 1235
***************************************