[29979] in Perl-Users-Digest
Perl-Users Digest, Issue: 1222 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 22 11:09:47 2008
Date: Tue, 22 Jan 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 Tue, 22 Jan 2008 Volume: 11 Number: 1222
Today's topics:
Re: A do-file location: how the code inside that do-fil <bik.mido@tiscalinet.it>
Re: Activestate help files calling out <g_m@remove-comcast.net>
Re: Chat client/server print failed <deadpickle@gmail.com>
Electronic and Computer Science video courses, No login <Arao44@gmail.com>
Re: Electronic and Computer Science video courses, No l <Arao44@gmail.com>
Re: File Monitoring modules nagandla@gmail.com
Re: File Monitoring modules <ben@morrow.me.uk>
Re: File Monitoring modules nagandla@gmail.com
Re: File Monitoring modules <Peter@PSDT.com>
little problem with xml::dom::parser <wuendi@googlemail.com>
Re: More perl tutorials <thepoet_nospam@arcor.de>
Re: sprintf rouding error <check.sig@for.email.invalid>
Re: sprintf rouding error <joost@zeekat.nl>
Re: sprintf rouding error Broki@gmx.de
Re: sprintf rouding error <joost@zeekat.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 22 Jan 2008 12:39:00 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: A do-file location: how the code inside that do-file find it?
Message-Id: <qclbp3d3fprad36gp29cnm6r299up7kta1@4ax.com>
On Mon, 21 Jan 2008 15:02:46 -0800 (PST), "comp.llang.perl.moderated"
<ced@blv-sam-01.ca.boeing.com> wrote:
>I would have thought 'FindBin' (perldoc FindBin) would have been the
>best answer if the former.
OTOH FindBin is somewhat bugged.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 22 Jan 2008 07:26:03 -0500
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: Activestate help files calling out
Message-Id: <2vadnWpk55crQwjanZ2dnUVZ_jednZ2d@comcast.com>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message news:Xns9A2D3B4ED4C78asu1cornelledu@127.0.0.1...
> "~greg" <g_m@remove-comcast.net> wrote in
> news:PNOdnSvNGaMnOgjanZ2dnUVZ_uqvnZ2d@comcast.com:
>
>>
>> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
>> news:Xns9A2CB74BBE4C4asu1cornelledu@127.0.0.1...
>>> "~greg" <g_m@remove-comcast.net> wrote in
>>> news:RKudnf6AesEoAAnanZ2dnUVZ_uCinZ2d@comcast.com:
>>>
>>>> Anyone know why the activestate help files call out over the
>>>> internet?
>>>
>>> What makes you think that? I have not noticed that. I have 5.8.8,
>>> maybe something changed in the new package?
>>>
>>> So, please describe what you are seeing and tell us the version you
>>> are using.
>
> ...
>
>> I have gone to 5.10. But it also happened in 5.8.
>> I think it's always happened.
>>
>> The symptom is that when I am off line,
>> then the help files take about 30 seconds to come up.
>>
>> Of course it's unlikely that anything is actually "calling out",
>> technically. It's probably just due to something external being
>> referenced. But if I knew what, then I could comment out the line.
>
> A cursory grep of all files in the html directory did not indicate to me
> that anything external was being referenced.
>
> I cannot see anything in the firewall log or netstat.
>
> At this point, my guess would be that something in your browser
> configuration requires a DNS lookup. Depending on your set up, it could
> be a number of things from IE trying to check for updates to Firefox
> trying to load live bookmarks. Have you ruled those possibilities out by
> seeing what happens if you double-click on Perl\html\blank.html and Perl
> \html\activeperl.html? Is there a difference in behavior?
>
>
> Sinan
Amazing! Thank you!
That helped me isolate the problem almost immediately.
And yes - it does occur on blank.html.
And the only obvious thing in blank.html
is the comment
<!-- saved from url=(0017)http://localhost/ -->
between <html> and <head>
Removing that comment, removes the problem!
~~
Searching on it, I found that this is in fact some kind
of XP SP2 security feature (--or security feature workaround!)
(quoting from here: http://weblogs.macromedia.com/jd/archives/2004/08/mark_of_the_web.cfm )
- SP2's new "local machine lockdown" shows an alert
- when an ActiveX Control is requested for local files.
- Cure:
- You can add a "Mark of the Web" comment line to HTML files
- to preview them locally without alerts,
- such as "<!-- saved from URL [length of URL] [address of URL] -->".
Exactly *what's* happening, I don't know.
But that is definitely *where* it's happening.
Thank you!
~greg
------------------------------
Date: Tue, 22 Jan 2008 07:55:23 -0800 (PST)
From: deadpickle <deadpickle@gmail.com>
Subject: Re: Chat client/server print failed
Message-Id: <4a8dec40-3ab1-4b0a-b8c5-c8339b5a206f@e25g2000prg.googlegroups.com>
Thanks for the help, I think your right about a timer being a bad
choice. I added the lines, and edited them, to the program. When I ran
the client I got an error that was referenced to the add_watch of the
Gtk2::Helper (located in the connect_server sub):
*** unhandled exception in callback:
*** Not a GLOB reference at chat-client.pl line 120.
*** ignoring at chat-client.pl line 67.
I have gotten these errors before but I don't understand what they
mean or how I fixed them. I reposted the program with the new code.
I'm not sure if I got it implemented correctly.
#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 -init;
use Glib qw/TRUE FALSE/;
use IO::Socket::INET;
use Tie::RefHash;
use IO::Select;
use Gtk2::Helper;
#global variables
my $buffer;
my $host = "Deadpickle-hobo";
my $port = 6666;
my $conn_stat = 'idle';
my %inbuffer = ();
my %outbuffer = ();
my %ready = ();
my $select;
my $conn;
my $user;
#the main chat widget
my $main_window = Gtk2::Window->new("toplevel");
$main_window->signal_connect(delete_event => sub {Gtk2->main_quit;});
$main_window->set_default_size(250, 200);
my $table = Gtk2::Table->new(4, 2, FALSE);
$buffer = Gtk2::TextBuffer->new;
my $button = Gtk2::Button->new("Send");
my $entry = Gtk2::Entry->new();
my $label = Gtk2::Label->new("Chat Client Test");
my $textview = Gtk2::TextView->new_with_buffer($buffer);
$textview->set_cursor_visible (FALSE);
my $swindow = Gtk2::ScrolledWindow->new( undef, undef);
$swindow->set_policy( 'automatic', 'automatic');
$swindow->set_shadow_type( 'etched-out');
$swindow->add( $textview);
$table->attach_defaults($label, 0, 1, 0, 1);
$table->attach_defaults($swindow, 0, 2, 1, 3);
$table->attach_defaults($entry, 0, 1, 3, 4);
$table->attach_defaults($button, 1, 2, 3, 4);
$main_window->add($table);
$main_window->show_all();
$button->signal_connect("clicked" => sub { send_msg_all($entry-
>get_text); $entry->set_text('');} );
#run the login dialog
dialog($buffer);
Gtk2->main;
#-------------------Login Dialog-------------------
sub dialog{
my $buffer = shift;
my $dialog_window = Gtk2::Window->new('toplevel');
$dialog_window->signal_connect(delete_event => sub {Gtk2-
>main_quit});
my $dialog_table = Gtk2::Table->new(2, 2, FALSE);
my $dialog_label1 = Gtk2::Label->new('Chat Login:');
my $dialog_label2 = Gtk2::Label->new('User:');
my $dialog_label3 = Gtk2::Label->new('Host:');
my $chat_user = Gtk2::Entry->new();
$chat_user->set_text('');
my $dialog_button1 = Gtk2::Button->new('Connect');
$dialog_table->attach_defaults($dialog_label1, 0, 1, 0, 1);
$dialog_table->attach_defaults($chat_user, 1, 2, 0, 1);
$dialog_table->attach_defaults($dialog_button1, 1, 2, 1, 2);
$dialog_button1->signal_connect("clicked" => sub {$user = $chat_user-
>get_text; $dialog_window->destroy; my $msg = "Username: $user...";
&update_buffer($msg); connect_server()});
$dialog_window->add($dialog_table);
$dialog_window->show_all;
return 1;
}
#------------------Connect to server---------------------
#establishes connection to the server
sub connect_server{
if ($conn_stat ne 'connected') {
$buffer->insert(($buffer->get_end_iter), "Connecting to Server
$host:$port...\n");
$conn = IO::Socket::INET->new(PeerAddr => $host, PeerPort =>
$port, Proto => 'tcp') or popup_err(1);
if ($conn) {
%inbuffer = ();
%outbuffer = ();
%ready = ();
tie %ready, 'Tie::RefHash';
nonblock($conn);
$select = IO::Select->new($conn);
$conn_stat = 'connected';
&update_buffer(my $msg = "Connected!");
#send login to server
send_login();
Gtk2::Helper->add_watch ( fileno $select, 'in',sub{ my ($fh) =
@_; \&wait_for_msg($fh);},$select);
}
}
return 1;
}
#-------------------Error popup-------------------
# pops up an error message
sub popup_err{
my ($error_code) = @_;
my $error;
if ($error_code == 1) {$error = "Cannot create Socket!"}
elsif ($error_code == 2) {$error = "Username to Short!"}
elsif ($error_code == 3) {$error = "No connection Established!"}
elsif ($error_code == 4) {$error = "Already Logged on with This User
Name!"}
elsif ($error_code == 5) {$error = "Not Connected!"}
else {$error = "Unkown Error!"}
&update_buffer($error);
my $error_dialog = Gtk2::MessageDialog->new($main_window, 'destroy-
with-parent', 'error', 'ok', "$error");
$error_dialog->run;
$error_dialog->destroy;
return 1;
}
#-------------------blocking-------------------
# nonblock($socket) puts socket into nonblocking mode
sub nonblock {
my $socket = shift;
$socket->blocking(0);
return 1;
}
#-------------------Message Waiting-------------------
# Wait for incoming messages from the server relayed from clients
sub wait_for_msg {
my ($fh) = @_;
my $msg;
$fh->recv($msg, 'POSIX::BUFSIZ', 0) or die "recv: $!";
print $msg."\n";
while ($inbuffer{$fh} =~ s/(.*\n)//) {
push( @{$ready{$fh}}, $1 );
}
foreach $fh (keys %ready) {
handle($fh);
}
return 1;
}
#-------------------Handler-------------------
# handle($socket) deals with all pending requests for $client
sub handle {
my $server = shift;
my $request;
foreach $request (@{$ready{$server}}) {
chomp $request;
process_incoming($server, $request);
}
delete $ready{$server};
return 1;
}
#-------------------Process Incoming-------------------
sub process_incoming {
my ($server, $msg) = @_;
my @logged_users;
my @rcvd_msg = split(/::/, $msg);
print "@rcvd_msg\n";
if ($rcvd_msg[1] eq "1") {
if($rcvd_msg[2] eq "03") {
print "Successfully Logged in!\n";
} elsif ($rcvd_msg[2] eq "12") {
popup_err(4);
} else {
# Create pop-up for error!
print "Error Logging in ", $msg, "\n";
popup_err(5);
}
}
elsif ($rcvd_msg[1] eq "7") {
# receive global message
print "$msg\n";
rcv_msg_all($rcvd_msg[3], $rcvd_msg[4]);
} else {
print "Unrecognized response: $msg\n";
exit(0);
}
return 1;
}
#-------------------Send message to all-------------------
sub send_msg_all {
my ($msg) = @_;
print "$conn\n";
if(defined $conn) {
# Send a the Message to server
print "Sending\n";
print $conn "7\:\:$user\:\:$msg\n";
} else {
popup_err(3);
}
return 1;
}
#-------------------Send login-------------------
#logs the user name on the server
sub send_login {
# my ($u) = @_;
if(defined $conn) {
if(length($user) > 0) {
#send login to server
print $conn "1\:\:$user\n";
} else {
popup_err(2);
}
} else {
popup_err(3);
}
return 1;
}
#-------------------Display All Message-------------------
sub rcv_msg_all {
my ($from, $msg) = @_;
print "Received Global message:\n";
if(defined $conn) {
print "Already Connected: Proceeding with message!\n";
$buffer->insert(($buffer->get_end_iter), "$from: $msg\n");
} else {
print "No connection established!\n";
popup_err(3);
}
return 1;
}
#-------------------Print messages to the widget-------------------
sub update_buffer {
my ($msg) = @_;
$buffer->insert(($buffer->get_end_iter), "$msg\n");
return 1;
}
------------------------------
Date: Tue, 22 Jan 2008 04:19:08 -0800 (PST)
From: AK444 <Arao44@gmail.com>
Subject: Electronic and Computer Science video courses, No login, No fee
Message-Id: <82fae10f-1bb2-4204-bab6-c2ba8f1a334b@k39g2000hsf.googlegroups.com>
Hi Guys
Good news is 23 Electronic and Computer Science video courses
are free, No login, No fee. All you need to have is real player
installed on your PC.
Electronics is at
http://freevideolectures.com/electronics/circuits_and_electronics.php
Computer Science is at http://freevideolectures.com/ComputerScience/Computer_System_Engineer...
Keep Learning..........
Bye
------------------------------
Date: Tue, 22 Jan 2008 04:20:20 -0800 (PST)
From: AK444 <Arao44@gmail.com>
Subject: Re: Electronic and Computer Science video courses, No login, No fee
Message-Id: <715320d1-74cc-499c-b33d-f193c6fb7a9e@e25g2000prg.googlegroups.com>
Sorry
Computer Science is http://freevideolectures.com/ComputerScience/Computer_System_Engineering.php
------------------------------
Date: Tue, 22 Jan 2008 03:33:38 -0800 (PST)
From: nagandla@gmail.com
Subject: Re: File Monitoring modules
Message-Id: <2682ad1d-9c39-417f-bf7c-0b9b42966bc0@d4g2000prg.googlegroups.com>
On Jan 22, 3:08 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth nagan...@gmail.com:
>
>
>
> > For monitoring files in directories i am using SGI::FAM module...
> > this module is monitoring perfectlt but taking more 90% CPU usage
> > while monitoring ...
>
> It is polling, rather than using a kernel-based notification mechanism.
> What OS are you on?
>
> > so any one can suggest me the better module to monitor the files in
> > directoties....
>
> There are OS-specific interfaces to most of the file-change services I
> know of (kqueue, inotify, Win32's ChangeNotify). If you know what your
> OS supports, you can search for a direct interface to that.
>
> > here one more thing i want to monitor more than a
> > single directory at a time...
>
> All of the above will do that.
>
> Ben
My OS is Linux,,Dapper Drake Ubuntu System
------------------------------
Date: Tue, 22 Jan 2008 13:16:18 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: File Monitoring modules
Message-Id: <2u6h65-40q.ln1@osiris.mauzo.dyndns.org>
Quoth nagandla@gmail.com:
> On Jan 22, 3:08 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth nagan...@gmail.com:
> >
> > > For monitoring files in directories i am using SGI::FAM module...
> > > this module is monitoring perfectlt but taking more 90% CPU usage
> > > while monitoring ...
> >
> > It is polling, rather than using a kernel-based notification mechanism.
> > What OS are you on?
>
> My OS is Linux,,Dapper Drake Ubuntu System
Huh. fam(3) ought to work perfectly well under Linux... If you write a
minimal C program which watches the same directories, does it have the
same behaviour? If so, this is a problem with fam on your system, and
you need to take it up with the developers, if there are any. If there
are, they'll probably tell you to switch to gamin; making SGI::FAM work
with gamin has been on my todo list for a while now... :)
Ben
------------------------------
Date: Tue, 22 Jan 2008 05:25:31 -0800 (PST)
From: nagandla@gmail.com
Subject: Re: File Monitoring modules
Message-Id: <f2d98ee5-488e-4669-b42e-992eed2c2fe2@i12g2000prf.googlegroups.com>
On Jan 22, 6:16 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth nagan...@gmail.com:
>
> > On Jan 22, 3:08 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > > Quoth nagan...@gmail.com:
>
> > > > For monitoring files in directories i am using SGI::FAM module...
> > > > this module is monitoring perfectlt but taking more 90% CPU usage
> > > > while monitoring ...
>
> > > It is polling, rather than using a kernel-based notification mechanism.
> > > What OS are you on?
>
> > My OS is Linux,,Dapper Drake Ubuntu System
>
> Huh. fam(3) ought to work perfectly well under Linux... If you write a
> minimal C program which watches the same directories, does it have the
> same behaviour? If so, this is a problem with fam on your system, and
> you need to take it up with the developers, if there are any. If there
> are, they'll probably tell you to switch to gamin; making SGI::FAM work
> with gamin has been on my todo list for a while now... :)
>
> Ben
Ya thank U Ben,
Just now i found one more module for monitoring is File::Monitor....
It is also all most all same as fam...and also taking equivalent time
to moniotr when a file is newly created or deleted....
and also it is taking very less CPU usage (below 20%) while monitoring
directories...
Have a look on that....and suggest me that whether can i use that...
------------------------------
Date: Tue, 22 Jan 2008 13:34:57 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: File Monitoring modules
Message-Id: <pan.2008.01.22.13.34.56.906617@PSDT.com>
On Mon, 21 Jan 2008 23:29:20 -0800, nagandla wrote:
> For monitoring files in directories i am using SGI::FAM module...
> this module is monitoring perfectlt but taking more 90% CPU usage
> while monitoring ...
> so any one can suggest me the better module to monitor the files in
> directoties....here one more thing i want to monitor more than a
> single directory at a time...
Maybe
http://search.cpan.org/~twerner/Linux-Inotify-0.05/lib/Linux/Inotify.pm
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: Tue, 22 Jan 2008 06:39:29 -0800 (PST)
From: "=?ISO-8859-1?Q?mathias_w=FCndisch?=" <wuendi@googlemail.com>
Subject: little problem with xml::dom::parser
Message-Id: <a1a5d1ec-10e8-4f23-a01e-29eb3d085f66@y5g2000hsf.googlegroups.com>
dear group,
i have a little problem with the automatic conversion from unicode
entities in real characters by XML::DOM::Parser (or XML::Parser). for
example i have the string '&x#A0;' in a xml source file and i want it
after parsing with XML::DOM::Parser also in the target xml file.
begin source file:
<?xml version=3D"1.0" encoding=3D"ISO-8859-1" standalone=3D"yes"?>
<doc>
<name>Mathias Wuendisch</name>
</doc>
end source file:
begin perl script:
#!c:\perl\bin\perl.exe -w
use XML::DOM;
use strict;
&process_file( shift @ARGV );
sub process_file {
my $infile =3D shift;
my $dom_parser =3D new XML::DOM::Parser(NoExpand =3D> 1,
ProtocolEncoding =3D> 'iso-8859-1', ParseParamEnt =3D> 0, ExpandParamEnt
=3D> 0) ;
my $doc =3D $dom_parser->parsefile( $infile ,NoExpand =3D> 1,
ParseParamEnt =3D> 0, ExpandParamEnt =3D> 0) ;
print $doc->toString;
$doc->dispose;
}
exit;
end perl script:
after: perl xml-dom-test.pl test.xml > test1.xml
i have this
begin target file:
<?xml version=3D"1.0" encoding=3D"ISO-8859-1" standalone=3D"yes"?>
<doc>
<name>Mathias=A0Wuendisch</name>
</doc>
end target file:
i've read the sourceforge faq and i've found a solution for "named
entities" like this:
---
<?xml version=3D"1.0" encoding=3D"ISO-8859-1" standalone=3D"yes"?>
<!DOCTYPE doc [
<!ENTITY nbsp " " >
]>
<doc>
<name>Mathias Wuendisch</name>
</doc>
---
ok, than the "named entity" is also in the target file... but
what is with "unnamed entities" like &x#A0; ? why did the NoExpand
flag or ExpandParamEnt flag not work for me? any suggestions?
kind regards,
mathias wündisch
------------------------------
Date: Tue, 22 Jan 2008 14:07:14 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: More perl tutorials
Message-Id: <4795ea8b$0$9117$9b4e6d93@newsspool2.arcor-online.net>
Michele Dondi wrote:
> I personally believe that golf is cool, and I wholeheartedly disagree
> with those that see in it a major risk for Perl. However I would also
> shy away from recommending it as a *learning tool*.
I'd say that depends on the type of learner. If one is the type
that needs a structured approach, then you're hundred percent
correct. For myself, I've found that a balanced mixture of
well-written books, practical applications and just-for-fun
puzzles works best. For the latter I've often picked some older
golf challenges because they're by design not overly complex and,
as the solutions show, can be heavily optimized. Solving those
has taught me some bits about memory efficiency or execution time.
Of course, I also admit that bringing up the topic of golfing was a
reason in itself for my posting ;)
-Chris
------------------------------
Date: Tue, 22 Jan 2008 13:27:29 +0200
From: Alex <check.sig@for.email.invalid>
Subject: Re: sprintf rouding error
Message-Id: <Aqklj.284653$Kq5.174914@reader1.news.saunalahti.fi>
Joost Diepenmaat wrote:
> Alex <check.sig@for.email.invalid> writes:
>> given no context at all, I'm fairly certain that mathematical rounding
>> defaults to the common method, which yields 6705. At least, this is
>> how I was taught in school.
> I was also taught this rule in school. I am pretty certain round-to-even
> is more common at least for statistical calculations.
Which is a specific application area and, as such, irrelevant to the
case. The OP stated clearly that rounding 6704.5 down was an error,
therefore indicating (which is the default *anyway*) that the common
method is the method of choice.
Alex
--
localpart = alext
domain = iki dot fi
email = localpart at domain
------------------------------
Date: Tue, 22 Jan 2008 13:04:15 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: sprintf rouding error
Message-Id: <877ii283sw.fsf@zeekat.nl>
Alex <check.sig@for.email.invalid> writes:
> Joost Diepenmaat wrote:
>> Alex <check.sig@for.email.invalid> writes:
>>> given no context at all, I'm fairly certain that mathematical rounding
>>> defaults to the common method, which yields 6705. At least, this is
>>> how I was taught in school.
>
>> I was also taught this rule in school. I am pretty certain round-to-even
>> is more common at least for statistical calculations.
>
> Which is a specific application area and, as such, irrelevant to the
> case. The OP stated clearly that rounding 6704.5 down was an error,
> therefore indicating (which is the default *anyway*) that the common
> method is the method of choice.
Well, *mathematics* is a specific application area. Most computer
programs aren't about math per se.
Round-to-even is what I expect from floating point rounding on a
computer, unless the language specifies otherwise, since it's the
default IEEEE rounding.
I don't see where in this thread it's made clear that rounding down is
an error, though it may well be for the OP's program. I only see that
the result is unexpected, so I tried to explain a bit more about the
reasoning behind this unexpected rounding.
Joost.
------------------------------
Date: Tue, 22 Jan 2008 06:10:27 -0800 (PST)
From: Broki@gmx.de
Subject: Re: sprintf rouding error
Message-Id: <f2c1db23-849d-40c1-a073-35c1d7565708@h11g2000prf.googlegroups.com>
Thanks for your replies.
To reduce the problem I will try to use expressions like 115/100 than
1.15.
The rounded down 6704 is an error in the eyes of my boss - so it=B4s not
only unexpected - it=B4s an error for me.
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?
Goetz
On 22 Jan., 13:04, Joost Diepenmaat <jo...@zeekat.nl> wrote:
> Alex <check....@for.email.invalid> writes:
> > Joost Diepenmaat wrote:
> >> Alex <check....@for.email.invalid> writes:
> >>> given no context at all, I'm fairly certain that mathematical rounding=
> >>> defaults to the common method, which yields 6705. At least, this is
> >>> how I was taught in school.
>
> >> I was also taught this rule in school. I am pretty certain round-to-eve=
n
> >> is more common at least for statistical calculations.
>
> > Which is a specific application area and, as such, irrelevant to the
> > case. The OP stated clearly that rounding 6704.5 down was an error,
> > therefore indicating (which is the default *anyway*) that the common
> > method is the method of choice.
>
> Well, *mathematics* is a specific application area. Most computer
> programs aren't about math per se.
>
> Round-to-even is what I expect from floating point rounding on a
> computer, unless the language specifies otherwise, since it's the
> default IEEEE rounding.
>
> I don't see where in this thread it's made clear that rounding down is
> an error, though it may well be for the OP's program. I only see that
> the result is unexpected, so I tried to explain a bit more about the
> reasoning behind this unexpected rounding.
>
> Joost.
------------------------------
Date: Tue, 22 Jan 2008 15:42:54 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: sprintf rouding error
Message-Id: <871w899b0x.fsf@zeekat.nl>
Broki@gmx.de writes:
> Thanks for your replies.
> To reduce the problem I will try to use expressions like 115/100 than
> 1.15.
If I understand you correctly, I think that won't make any
difference. I'm sure it won't once you assign 115/100 to a variable;
perl doesn't handle rational numbers natively. You may want to use the
(math)bigrat modules if you want *EXACT* results (provided ofcourse that
your calculations use rational numbers only).
If you mean to use cents or mils as the base unit (you mention currency
in one of your posts) for all calculations that will help, since that
way at least you can exactly specify prices in that unit without
floating point errors. You should still mind divisions or multiplying
with floats.
> The rounded down 6704 is an error in the eyes of my boss - so it´s not
> only unexpected - it´s an error for me.
int($val+0.5) should do what you want for positive numbers, I guess. you
may also want to take a look at POSIX's ceil(), and Math::Round on CPAN.
Does your boss wants you to round -1.5 to -2 or -1?
> 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?
For some sets of data, yes. It obviously won't work that way for floats
in the range 0 .. 1.
See also Math::Round's round_rand.
Joost.
------------------------------
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 1222
***************************************