[24554] in Perl-Users-Digest
Perl-Users Digest, Issue: 6732 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 26 03:05:33 2004
Date: Sat, 26 Jun 2004 00:05:07 -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 Sat, 26 Jun 2004 Volume: 10 Number: 6732
Today's topics:
Re: error logs... <johnjcarbone@nospam.hotmail.com>
Re: error logs... <johnjcarbone@nospam.hotmail.com>
Re: error logs... <johnjcarbone@nospam.hotmail.com>
use integer != int() (suedecold)
Re: use integer != int() <tassilo.parseval@rwth-aachen.de>
Re: use integer != int() <tallpeak@hotmail.NO.SPAM>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 26 Jun 2004 06:15:07 GMT
From: "John ©" <johnjcarbone@nospam.hotmail.com>
Subject: Re: error logs...
Message-Id: <Lv8Dc.4848$aJ3.2277@nwrdny02.gnilink.net>
<nobull@mail.com> wrote in message
news:4dafc536.0406250452.18bbc62d@posting.google.com...
> "John ©" <johnjcarbone@nospam.hotmail.com> wrote in message
news:<04GCc.4775$A9.1422@nwrdny01.gnilink.net>...
Wow. I didn't think it would be that big a deal. Let it go. Sorry that my
posting here caused such grief ... funny how although you thought you were
helpful, someone else named you a 'bully'. But that's beside the point, I
should have counted to ten before I posted that line (GUIDELINES).
But again, sorry I was rude with my ignorance. It won't happen again.
Cheers,
John
------------------------------
Date: Sat, 26 Jun 2004 06:27:34 GMT
From: "John ©" <johnjcarbone@nospam.hotmail.com>
Subject: Re: error logs...
Message-Id: <qH8Dc.5535$Xn.5288@nwrdny03.gnilink.net>
"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:Xns9513421EE1957ebohlmanomsdevcom@130.133.1.4...
> "John ©" <johnjcarbone@nospam.hotmail.com> wrote in
> news:rxKCc.4476$L8.3152@nwrdny02.gnilink.net:
> Usenet newsgroups (and for that matter, Usenet itself) have
characteristics
> that meet many of the anthropological criteria for cultures. When
visiting
> a foreign culture, it is normally considered necessary to make at least
> some effort to familiarize oneself with it. For example, an American who
> visits England and is surprised, or worse, indignant to find out that
> people drive on the left side of the road hasn't put in that effort.
There
> is a stereotype that says that most Americans behave that way (we mostly
> don't but the squeaky wheel gets the grease) and in fact it has a name:
the
> "ugly American." You're showing some signs of it.
Usenet is a culture? Sorry if I didn't realize that looking up something on
my own personal computer was actually taking me (and it seems invading)
another culture. Is there an embassy here where I can find sanctuary?
I like the England analogy, unfortunately I am not in England, I am in my
house. Didn't think my computer was to be treated like another country.
I am not trying to be rude, nor am I trying to get people upset, but I feel
the attacks are unnecessary. Like I said, I was not one person doing it a
thousand times, I was one of the thousands of people who did it once.
But whatever, I am not going to argue anymore, I understand I didn't follow
the guidelines (not rules mind you) and I am sorry for that. The only thing
that bothers me is when people would rather berate than help. Would you
smack a newborn in the head for not knowing how to talk right out of the
womb? (There's an analogy for you).
So again, sorry that I caused such pain. I'll walk the straight and narrow
from now on and hopefully I won't step on any toes... and if it's too late
for me, don't hold it against any other Americans.
Cheers,
John
------------------------------
Date: Sat, 26 Jun 2004 06:31:30 GMT
From: "John ©" <johnjcarbone@nospam.hotmail.com>
Subject: Re: error logs...
Message-Id: <6L8Dc.3299$Av3.1096@nwrdny01.gnilink.net>
"Brian McCauley" <nobull@mail.com> wrote in message
news:u9zn6rwl8y.fsf@wcl-l.bham.ac.uk...
> Yes, I must confess, that I tend to assume that people who come here
> and behave this way are Americans.
'behave this way'? Exactly what way was I behaving... all I did was ask for
people not to be rude. Is that such a crime?
So I'll add you to my list of people I am sorry to. Sorry that I may have
offended you with my ignorant actions here. I am truly sorry. I'll try to be
better.
Cheers,
John
------------------------------
Date: 25 Jun 2004 23:03:01 -0700
From: suedecold@yahoo.com (suedecold)
Subject: use integer != int()
Message-Id: <8dce2b7b.0406252119.4c065260@posting.google.com>
I should have left it alone but I decided to clean up
a script and replace a number of calls to "int()" in a
subroutine with "use integer".
I do not understand why I am getting different
results with the following code...
-------------------- begin script --------------------
use strict;
&method_a(730791);
&method_b(730791);
exit;
sub method_a {
my($g) = @_;
my $y;
$y = int((10000*$g + 14780)/3652425);
printf STDOUT "Method A = %d\n", $y;
}
sub method_b {
use integer;
my($g) = @_;
my $y;
$y = (10000*$g + 14780)/3652425;
printf STDOUT "Method B = %d\n", $y;
}
-------------------- end script --------------------
When I run it I get the following on my Win2K box:
C:\Perl\bin>buggy.pl
Method A = 2000
Method B = -351
I thought I understood "use integer" but maybe I
don't. Would someone care to explain the reason for the
different results? perl -v produces:
This is perl, v5.8.3 built for MSWin32-x86-multi-thread
(with 8 registered patches, see perl -V for more detail)
Copyright 1987-2003, Larry Wall
Binary build 809 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Feb 3 2004 00:28:51
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.com/, the Perl Home Page.
TIA,
JAPH wannabe
------------------------------
Date: Sat, 26 Jun 2004 08:37:25 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: use integer != int()
Message-Id: <2k4jt7F17vlojU1@uni-berlin.de>
Also sprach suedecold:
> I should have left it alone but I decided to clean up
> a script and replace a number of calls to "int()" in a
> subroutine with "use integer".
>
> I do not understand why I am getting different
> results with the following code...
>
> -------------------- begin script --------------------
> use strict;
>
> &method_a(730791);
> &method_b(730791);
>
> exit;
>
> sub method_a {
> my($g) = @_;
> my $y;
> $y = int((10000*$g + 14780)/3652425);
> printf STDOUT "Method A = %d\n", $y;
> }
>
> sub method_b {
> use integer;
> my($g) = @_;
> my $y;
> $y = (10000*$g + 14780)/3652425;
> printf STDOUT "Method B = %d\n", $y;
> }
> -------------------- end script --------------------
>
> When I run it I get the following on my Win2K box:
>
> C:\Perl\bin>buggy.pl
> Method A = 2000
> Method B = -351
>
> I thought I understood "use integer" but maybe I
> don't. Would someone care to explain the reason for the
> different results? perl -v produces:
When you 'use integer' you don't actually tell perl to truncate all
numbers. You tell it to use the machine's native integers. On most
machines, those would be 32bit integers. Such integers are too small to
store 730791*10000 and so the value wraps around and you get something
negative.
'int' on the other hand does something else. Perl will internally still
be using doubles if the values are too large to fit into an integer.
'int' only chops off the decimal part, but the value remains a double
and hence has a larger range than a 32bit int.
So regrettably, you make your scripts a little less portable when using
integer.pm since they now are more dependent on the width of your
integers.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 26 Jun 2004 00:00:57 -0700
From: "Aaron W. West" <tallpeak@hotmail.NO.SPAM>
Subject: Re: use integer != int()
Message-Id: <-LKdnQys3NuzgkDdRVn-ug@speakeasy.net>
It's overflowing the maximum value of an integer on your system. On 32-bit
machines, integers range from -2**31 to 2**31-1. (Exponentiation, however,
seems to switch to floating-point automatically when I compute 2**31.) When
I installed Cygwin Perl, it was compiled with 64-bit integer support, but
the version I have installed now (5.8.4), I compiled to use 32-bit ints.
Perl can emulate 64-bit integers on 32-bit machines, and if you had a
version compiled that way, the following calculation result should be
positive:
$ perl -e 'use integer; print 65536*32768'
-2147483648
$ /usr/bin/perl -e 'use integer; print 65536*32768'
2147483648
$ perl -v
This is perl, v5.8.4 built for cygwin
...
$ /usr/bin/perl -v
This is perl, v5.8.2 built for cygwin-thread-multi-64int
...
Modern computers (all pentiums) are just about as fast for floating-point
math, usually, so I think there's rarely any reason to bother with use
integer.
I really think in most cases if you feel the need to "use integer" you
should first ask if the small speed difference makes any difference to your
app/users, and secondly if you should switch to a compiled language for some
speed-critical portion of the application if so.
Nevertheless, I played with it for a bit...
$ time perl -e 'for(1..10000000) {$i++; $s+=$i}; '
real 0m4.062s
user 0m3.705s
sys 0m0.130s
$ time perl -e 'use integer; for(1..10000000) {$i++; $s+=$i}; '
real 0m3.898s
user 0m3.414s
sys 0m0.170s
It's slightly faster with "use integer" (by about 16 nanoseconds per
iteration on an Athlon XP 2400). But $s overflowed and became negative
(-2004260032 for the version with use integer, 50000005000000 without.)
$ time perl -e 'for $x (1..1000){ for $y (1..1000) {$s=$x*$y}}'
real 0m0.546s
user 0m0.380s
sys 0m0.140s
$ time perl -e 'use integer;for $x (1..1000){ for $y (1..1000) {$s=$x*$y}}'
real 0m0.512s
user 0m0.340s
sys 0m0.160s
$ time perl -e 'use integer;for $x (1..1000){ for $y (1..1000) {$s=$x*$y}}'
real 0m0.501s
user 0m0.310s
sys 0m0.120s
This time I avoided overflowing calculations. The difference is still very
small, .011 microseconds per iteration.
$ perl -e 'use Benchmark; timethese(10000000,
{"fmul" => sub { $x=3; $x=$x*$x*$x*$x*$x*$x*$x*$x*$x},
"imul" => sub {use integer; $x=3; $x=$x*$x*$x*$x*$x*$x*$x*$x*$x} });'
Benchmark: timing 10000000 iterations of fmul, imul...
fmul: 11 wallclock secs (10.56 usr + 0.00 sys = 10.56 CPU) @
947418.29/s
(n=10000000)
imul: 9 wallclock secs ( 7.56 usr + 0.00 sys = 7.56 CPU) @
1322576.38/s
(n=10000000)
Oh, and on ActiveState (I was using Cygwin perl compiled with 32-bit ints.)
$ c:/perl/bin/perl -e 'use Benchmark; timethese(10000000,
{"fmul" => sub { $x=3; $x=$x*$x*$x*$x*$x*$x*$x*$x*$x},
"imul" => sub {use integer; $x=3; $x=$x*$x*$x*$x*$x*$x*$x*$x*$x} });'
Benchmark: timing 10000000 iterations of fmul, imul...
fmul: 10 wallclock secs (10.09 usr + 0.01 sys = 10.10 CPU) @
989609.10/s
(n=10000000)
imul: 9 wallclock secs ( 8.07 usr + 0.00 sys = 8.07 CPU) @
1238850.35/s
(n=10000000)
------------------------------------------------------------------
"suedecold" <suedecold@yahoo.com> wrote in message
news:8dce2b7b.0406252119.4c065260@posting.google.com...
I should have left it alone but I decided to clean up
a script and replace a number of calls to "int()" in a
subroutine with "use integer".
I do not understand why I am getting different
results with the following code...
-------------------- begin script --------------------
use strict;
&method_a(730791);
&method_b(730791);
exit;
sub method_a {
my($g) = @_;
my $y;
$y = int((10000*$g + 14780)/3652425);
printf STDOUT "Method A = %d\n", $y;
}
sub method_b {
use integer;
my($g) = @_;
my $y;
$y = (10000*$g + 14780)/3652425;
printf STDOUT "Method B = %d\n", $y;
}
-------------------- end script --------------------
When I run it I get the following on my Win2K box:
C:\Perl\bin>buggy.pl
Method A = 2000
Method B = -351
I thought I understood "use integer" but maybe I
don't. Would someone care to explain the reason for the
different results? perl -v produces:
This is perl, v5.8.3 built for MSWin32-x86-multi-thread
(with 8 registered patches, see perl -V for more detail)
Copyright 1987-2003, Larry Wall
Binary build 809 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Feb 3 2004 00:28:51
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.com/, the Perl Home Page.
TIA,
JAPH wannabe
------------------------------
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 V10 Issue 6732
***************************************