[8672] in Perl-Users-Digest
Perl-Users Digest, Issue: 2289 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 10 09:07:29 1998
Date: Fri, 10 Apr 98 06:01:02 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 10 Apr 1998 Volume: 8 Number: 2289
Today's topics:
Re: Bill Gates should be invited to O'Reilly's "Free So (Stefaan A Eeckels)
Re: Bill Gates should be invited to O'Reilly's "Free So (Chris Nandor)
Re: Bill Gates should be invited to O'Reilly's "Free So <jdporter@min.net>
Re: Easy package/sub-routine ? <WS010@dvvlap.be>
Re: File Locking with tied [GNS]?DBM files... <sbekman@iil.intel.com>
How to get only 2 decimal notation? (Apisilp Trunganont)
Re: How to get only 2 decimal notation? <sneaker@mediaone.net>
Re: How to get only 2 decimal notation? <coffman@value.net>
Re: How to get only 2 decimal notation? <grinch@whoville.com>
Re: How to get only 2 decimal notation? <perlguy@inlink.com>
Re: How to get only 2 decimal notation? (Mike Heins)
Re: How to get only 2 decimal notation? <grinch@whoville.com>
Re: How to get only 2 decimal notation? (Casper H.S. Dik - Network Security Engineer)
Re: Looking for Polling/Voting CGI/java Script <ebohlman@netcom.com>
May can you help, please? <ben@wallroyds.demon.co.uk>
New error? I can't open a file to write! blr@mail.alarmix.net
Re: perl win 32 : asterisk on command line <kairys@mi.sl.com>
Re: perl win 32 : asterisk on command line <kairys@mi.sl.com>
Re: problem with output <perlguy@inlink.com>
Re: Random Banner Problem <sneaker@mediaone.net>
Relational Searching (Henry Lifton)
Re: RMS should be invited to O'Reilly's "Free Software <millNO@SPAMludd.luth.se>
Re: RMS should be invited to O'Reilly's "Free Software (Stefaan A Eeckels)
Re: rounding and precision <lr@hpl.hp.com>
Re: Week of Month (Robert F. Harrison)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Apr 1998 09:40:24 GMT
From: Stefaan.Eeckels@ecc.lu (Stefaan A Eeckels)
Subject: Re: Bill Gates should be invited to O'Reilly's "Free Software Summit" (was Re: RMS should be invited to O'Reilly's "Free Software Summit")
Message-Id: <6gkpe8$f4r$2@justus.ecc.lu>
In article <pudge-0904981259310001@dynamic500.ply.adelphia.net>,
pudge@pobox.com (Chris Nandor) writes:
> In article <6gi4ue$vrv$1@justus.ecc.lu>, Stefaan.Eeckels@ecc.lu (Stefaan A
> Eeckels) wrote:
>
> # I wonder if RMS ever anticipated that his 'free software' would
> # be the last bastion against Microsoft?
>
> HIS free software?
>
> Uhhhhhh ... as important as he is, he is not the owner of the movement,
> even if there is a movement.
Never meant to imply that - he's the figurehead of the movement,
(or the tendency :-) to release quality software with a license
that guarantees the availability of the source code.
I believe the GPL to be one of the main reasons for the
success of Linux (as oposed to the BSD386 derivatives),
even though the effect of the GPL is to severely restrict what
commercial companies can do with the code (they can't make it
proprietary, as happend with X ;-).
Would you object to 'his free software concept' ?
--
Stefaan
--
PGP key available from PGP key servers (http://www.pgp.net/pgpnet/)
___________________________________________________________________
"Don't worry about people stealing your ideas. If your ideas
are any good, you'll have to ram them down people's throats."
-- Howard Aiken
------------------------------
Date: Fri, 10 Apr 1998 11:40:47 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Bill Gates should be invited to O'Reilly's "Free Software Summit" (was Re: RMS should be invited to O'Reilly's "Free Software Summit")
Message-Id: <pudge-1004980740340001@dynamic500.ply.adelphia.net>
In article <6gjb6g$l8$1@nnrp1.dejanews.com>, ben@hayamasa.demon.co.uk wrote:
# In article <35317296.3189824@news.tornado.be>,
# bart.mediamind@tornado.be (Bart Lateur) wrote:
#
# > There is not ONE MS product that is not based on products that was
# > available before MS developed their own. You name it: OS (CP/M clone),
# > Windows (Mac and Xerox), spreadsheet, word processor, browser, server
# > software. First they imitate it, add some proprietary features, and then
# > compete the original manufacturer to death. Just look at what they're
# > trying to do to Netscape now.
#
# What I was refering to was taking something such as source code
# which is freely redistributable and turning it into
# something proprietory, which is quite a large part
# of O'Reilly's business.
One example, please? Just one?
You mentioned in e-mail that JPL was an example of this, because it is
built on something that is free, for something that is free, and it is
itself proprietary. That is nonsensical. If this were the case, then
every idea must be free to all, as every idea is built on other ideas that
were, are, or have been free.
If you believe that, which you must in order to be consistent, then fine;
but say that, so we can all judge your words fairly.
Maybe you mean the images on the fronts of the book? The Camel image was
public domain and is no more; aside from that, I can't see what you are
referring to, and if you must continue this defamation, I must demand that
you fully explain yourself.
--
Chris Nandor mailto:pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6'])
#== New Book: MacPerl: Power and Ease ==#
#== Publishing Date: Early 1998. http://www.ptf.com/macperl/ ==#
------------------------------
Date: Fri, 10 Apr 1998 12:27:26 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Bill Gates should be invited to O'Reilly's "Free Software Summit" (was Re: RMS should be invited to O'Reilly's "Free Software Summit")
Message-Id: <352E11A3.4813@min.net>
Chris Nandor wrote:
>
> Maybe you mean the images on the fronts of the book? The Camel image was
> public domain and is no more;
Now I'm confused. How can someone take a public domain image and make
it proprietary? Who did they buy the rights from? The public?
Also, where did you get your information? I don't see where (in the
book itself) it says the camel image on the cover is trademarked
property
of O'Reilly.
John Porter
------------------------------
Date: 10 Apr 1998 07:53:21 GMT
From: "WS010" <WS010@dvvlap.be>
Subject: Re: Easy package/sub-routine ?
Message-Id: <01bd6456$ae0aa460$8c7479c1@dvvbeint0ws010>
Try appending the following line to your .pm file anyway.
1;
------------------------------
Date: Fri, 10 Apr 1998 09:55:48 +0300
From: Bekman Stanislav <sbekman@iil.intel.com>
To: Brian Wheeler <bdwheele@indiana.edu>
Subject: Re: File Locking with tied [GNS]?DBM files...
Message-Id: <352DC274.41C6@iil.intel.com>
> When tying a hash to a DBM file, does any locking occur on the file
> when the value is updated or a key is added?
>
> If not, is there a easy way to do it, or do I have to wrap each hash modify
> with flock's?
See the 'Programming Perl' ed.2 : locking DataBases p. 392
______________________________________________________________________
Stas Bekman mailto:sbekman@iil.intel.com http://www.eprotect.com/stas
A must visit: http://www.eprotect.com/stas/TULARC (Java,CGI,PC,Linux)
Linux receives a 'Product of the Year Award' for Best Technical Support
http://www.infoworld.com/cgi-bin/displayTC.pl?97poy.supp.htm
------------------------------
Date: 10 Apr 1998 07:48:23 GMT
From: b39ast@nontri.ku.ac.th (Apisilp Trunganont)
Subject: How to get only 2 decimal notation?
Message-Id: <6gkis7$keg$1@news.ku.ac.th>
This is a very dummy question, but I don't know. I write this script.
$value = (27/126)*100;
print $value;
The output is 2.142857142857142705. But I want only 2.14. How to do this?
------------------------------
Date: Fri, 10 Apr 1998 09:56:55 GMT
From: Sneaker's Nest <sneaker@mediaone.net>
Subject: Re: How to get only 2 decimal notation?
Message-Id: <352DEB62.5145@mediaone.net>
Apisilp Trunganont wrote:
>
> This is a very dummy question, but I don't know. I write this script.
>
> $value = (27/126)*100;
> print $value;
>
> The output is 2.142857142857142705. But I want only 2.14. How to do this?
Part of the answer is here at -
Does perl have a round function? What about ceil() and floor()? Trig
functions?
For rounding to a certain number of digits, sprintf or printf is usually
the easiest route.
The POSIX module (part of the standard perl distribution) implements
ceil, floor, and a number of other
mathematical and trigonometric functions.
The Math::Complex module (part of the standard perl distribution)
defines a number of mathematical functions
that can also work on real numbers. It's not as efficient as the POSIX
library, but the POSIX library can't work
with complex numbers.
Rounding in financial applications can have serious implications, and
the rounding method used should be
specified precisely. In these cases, it probably pays not to trust
whichever system rounding is being used by Perl,
but to instead implement the rounding function you need yourself.
Does perl have a round function? What about ceil() and floor()? Trig
functions?
For rounding to a certain number of digits, sprintf or printf is usually
the easiest route.
The POSIX module (part of the standard perl distribution) implements
ceil, floor, and a number of other
mathematical and trigonometric functions.
The Math::Complex module (part of the standard perl distribution)
defines a number of mathematical functions
that can also work on real numbers. It's not as efficient as the POSIX
library, but the POSIX library can't work
with complex numbers.
Rounding in financial applications can have serious implications, and
the rounding method used should be
specified precisely. In these cases, it probably pays not to trust
whichever system rounding is being used by Perl,
but to instead implement the rounding function you need yourself.
But, someone else may have a
better answer, so keep watching :-)
Sneex
------------------------------
Date: 10 Apr 1998 11:02:40 GMT
From: Coffman <coffman@value.net>
Subject: Re: How to get only 2 decimal notation?
Message-Id: <6gku8g$egp$1@vnetnews.value.net>
Apisilp Trunganont <b39ast@nontri.ku.ac.th> wrote:
: This is a very dummy question, but I don't know. I write this script.
: $value = (27/126)*100;
: print $value;
: The output is 2.142857142857142705. But I want only 2.14. How to do this?
This will do it. See a C book on s/printf to determine how to get exactly
what you want.
$value = (27/126)*100;
print sprintf("%1.2f", $value);
Bill Coffman
------------------------------
Date: Fri, 10 Apr 1998 07:34:48 -0400
From: "Grinch" <grinch@whoville.com>
Subject: Re: How to get only 2 decimal notation?
Message-Id: <6gkvbl$64@fridge.shore.net>
Apisilp Trunganont wrote in message <6gkis7$keg$1@news.ku.ac.th>...
>This is a very dummy question, but I don't know. I write this script.
>
>$value = (27/126)*100;
>print $value;
>
>The output is 2.142857142857142705. But I want only 2.14. How to do this?
A couple of folks have mentioned using sprintf, so I won't repeat that.
You should be aware, however, that sprintf does not round off to a given
precision, it simply truncates any digits past a certain point. In other
words, 2.142 and 2.149 will both be displayed as 2.14 when using sprintf,
whereas when rounding the latter would result in 2.15.
Here's one way to round. It assumes that $value has already been calculated
as above:
$value = int($value * 100 + .5) / 100;
HTH!
-grinch
--
"Of course coffee doesn't make the world go around. It
just makes it go faster." - me
Sherm Pendley
grinch@whoville.com
http://www.whoville.com
------------------------------
Date: Fri, 10 Apr 1998 11:23:07 GMT
From: Brent Michalski <perlguy@inlink.com>
Subject: Re: How to get only 2 decimal notation?
Message-Id: <352E011B.A11A7C56@inlink.com>
try
printf ("%.2f",$value);
that should work for you.
Brent
------------------------------
Date: 10 Apr 98 11:55:29 GMT
From: mikeh@minivend.com (Mike Heins)
Subject: Re: How to get only 2 decimal notation?
Message-Id: <352e08b1.0@news.one.net>
Grinch <grinch@whoville.com> wrote:
> Apisilp Trunganont wrote in message <6gkis7$keg$1@news.ku.ac.th>...
>>This is a very dummy question, but I don't know. I write this script.
>>
>>$value = (27/126)*100;
>>print $value;
>>
>>The output is 2.142857142857142705. But I want only 2.14. How to do this?
> A couple of folks have mentioned using sprintf, so I won't repeat that.
> You should be aware, however, that sprintf does not round off to a given
> precision, it simply truncates any digits past a certain point. In other
> words, 2.142 and 2.149 will both be displayed as 2.14 when using sprintf,
> whereas when rounding the latter would result in 2.15.
That is not necessarily true -- it depends on your C library. In fact
it is almost always not true.
bill:/d% perl -e 'printf "%.2f\n", 2.146'
2.15
bill:/d%
It rounds at least on Linux, SunOS, Solaris, IRIX, BSD; and even on
Windows. I believe it does on any reasonable OS.
--
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
There ain't nothin' in this world 131 Willow Lane, Floor 2 | || _ \
that's worth being a snot over. Oxford, OH 45056 | || |_) |
--Larry Wall <mikeh@minivend.com> |___| _ <
513.523.7621 FAX 7501 |_| \_\
------------------------------
Date: Fri, 10 Apr 1998 08:27:13 -0400
From: "Grinch" <grinch@whoville.com>
Subject: Re: How to get only 2 decimal notation?
Message-Id: <6gl2ds$3ej@fridge.shore.net>
Mike Heins wrote in message <352e08b1.0@news.one.net>...
>That is not necessarily true -- it depends on your C library. In fact
>it is almost always not true.
>
>bill:/d% perl -e 'printf "%.2f\n", 2.146'
>2.15
>bill:/d%
Well, I'll be d**ned. I distinctly remember printf behaving the way I
described, quite some time ago. I can't recall which C compiler I was using
(Turbo C, I think...) , but it was definitely a 16-bit DOS compiler, which
goes to show how long ago it was.
Since the compiler claimed ANSI compliance, I just assumed that sprintf was
supposed to simply truncate, and never tried it again... And, of course, I
knew that Perl would use the C lib function, so assumed the same behaviour
for it.
Anyway, I stand corrected.
-grinch
--
"Of course coffee doesn't make the world go around. It
just makes it go faster." - me
Sherm Pendley
grinch@whoville.com
http://www.whoville.com
------------------------------
Date: 10 Apr 1998 12:25:14 GMT
From: Casper.Dik@Holland.Sun.Com (Casper H.S. Dik - Network Security Engineer)
Subject: Re: How to get only 2 decimal notation?
Message-Id: <casper.892211070@uk-usenet.uk.sun.com>
[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]
"Grinch" <grinch@whoville.com> writes:
>You should be aware, however, that sprintf does not round off to a given
>precision, it simply truncates any digits past a certain point. In other
>words, 2.142 and 2.149 will both be displayed as 2.14 when using sprintf,
>whereas when rounding the latter would result in 2.15.
Huh? Sprintf does round:
perl -e 'print sprintf("%.2f\n", 1.249)'
1.25
perl -e 'print sprintf("%.2f\n", 1.241)'
1.24
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
------------------------------
Date: Fri, 10 Apr 1998 07:18:02 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Looking for Polling/Voting CGI/java Script
Message-Id: <ebohlmanEr6sA2.DnC@netcom.com>
Jeff <jn1@outofservice.com> wrote:
: is it REQUIRD that a user can't somehow vote twice? that's almost
: impossible to do since the anonimity of the web will make hacking easy.
: what i've done (look at www.outofservice.com) is just track ip's. sure,
: someone can reconnect with a different IP and vote again... but that'd
: be work. it stops the not-so-serious ones.
It also stops legitimate first-time voters. On today's Internet, there
is *no* one-to-one correspondence between IP numbers and individual users.
Most dial-up servers dynamically assign IP numbers, so two users logging
on at different times may wind up with the same IP number.
------------------------------
Date: Fri, 10 Apr 1998 10:59:19 +0100
From: "bjf" <ben@wallroyds.demon.co.uk>
Subject: May can you help, please?
Message-Id: <892202490.7262.0.nnrp-06.c2de5b4a@news.demon.co.uk>
Hello all :-)
First of all, I want to thank to those who answer to my questions ...
All I need the code to do is, to see if the URL is out there or not. But,
this code doesn't work
Any suggestions, please can you give me some suggestions.
#!/usr/local/bin/perl
$theurl = qw(http://www.yahoo.com/index.html);
if (PING $theurl) {
print "The file is out there.";
}
else {
print "The file is NOT out there.";
}
# PING SUBROUTINE
sub PING
$_[0] =~ m!^(http):!;
}
exit;
Thanks for reading.
Regards
BJF
------------------------------
Date: Fri, 10 Apr 1998 06:01:56 -0600
From: blr@mail.alarmix.net
Subject: New error? I can't open a file to write!
Message-Id: <6gku75$upb$1@nnrp1.dejanews.com>
I'd like to create a file, but I can't. Here is the 2 line from one of my
CGI-script:
open(TCF,">$HOMEDIR/var/$tcf") || warn "Can't create $tcf.";
close(TCF);
The script running with suidperl. The real user id is 60 (httpd), the
effective user id is 98 (ovi).
The value of $HOMEDIR is /home/ovi
The user and group ovi has allowed to read and write to the /home/ovi/var
When I running the script, it's not create the file, no warning message in the
error log of httpd, and the script is exiting, I can't execute anything after
the open.
If I use the -w option with suidperl, and writing the filehandler with
lowercase letters, there's no warning message about it!
If anybody can help, please mail to me, because my news server halted.
blr@mail.alarmix.net
PS: Sorry, my english is very poor :(
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Thu, 9 Apr 1998 08:43:33 -0400
From: "Michael Kairys" <kairys@mi.sl.com>
Subject: Re: perl win 32 : asterisk on command line
Message-Id: <352ccead.0@news.ic.net>
I'm just a newbie, and hesitate to jump in where more experienced hands have
spoken, but I think you're all in the weeds. Did anyone *try* it?
> type foo.pl
foreach ( @ARGV ) { print "$_\n" }
> perl -w foo.pl -l thisarg -p * -u thatarg
-l
thisarg
-p
*
-u
thatarg
So much for Perl or the shell doing wildcard expansion. So what's happening?
I suspect the script itself is responsible. What is it doing with ARGV?
Perhaps it's invoking filename globbing with <>, e.g.
> type foo.pl
foreach ( <@ARGV> ) { print "$_\n" }
> dir /b
aaa
bbb
foo.pl
> perl -w foo.pl -l thisarg -p * -u thatarg
-l
thisarg
-p
aaa
bbb
foo.pl
-u
thatarg
------------------------------
Date: Thu, 9 Apr 1998 09:47:41 -0400
From: "Michael Kairys" <kairys@mi.sl.com>
Subject: Re: perl win 32 : asterisk on command line
Message-Id: <352cddb4.0@news.ic.net>
>-p means "loop through all of the lines in the specified file." (Like
>the -pi.bak we see in all those oneliners.) You're specifying "*", which to
>Win32 is the wildcard matching all filenames in a directory. So, Perl
>apparently thinks you want it to run through whatever directory you happen
>to be in and do somescript.pl to all of them.
Nope. Note the original command:
>>problem: perl -w somescript.pl -l thisarg -p * -u thatarg
The -p switch comes *after* the script file, and as such is handled by the
script, not Perl. Example:
In any case Perl does not behave as you hyothesize. Examples:
> perl -w -p * somescript.pl
Can't open perl script "*": Invalid argument
------------------------------
Date: Fri, 10 Apr 1998 11:36:13 GMT
From: Brent Michalski <perlguy@inlink.com>
Subject: Re: problem with output
Message-Id: <352E042C.24DD5551@inlink.com>
One thing I have done in the past, and it may not be the "best" way to
do it is to take the line in question and throw in a \n at each word
break after x number of characters.
read string character
are we at x chars yet?
- yes, is it a space?
- yes, replace the space with a \n
- no, read next char
continue loop
I don't have an example handy, but I hope I've pointed you in the right
direction.
Brent
------------------------------
Date: Fri, 10 Apr 1998 09:53:25 GMT
From: Sneaker's Nest <sneaker@mediaone.net>
Subject: Re: Random Banner Problem
Message-Id: <352DEA90.638B@mediaone.net>
Jeremy Hill wrote:
>
> Someone Please help me!
>
> I need a way to display random banners on a web page
> whenever someone goes to the page. I thought that
> I could just say
>
> <img src="MyScript.cgi">
>
Yes, this will work. I do this.
You need to use a random number generator,
specific to your development environment.
Could be done in any langauge, so -
Almost Off Topic... However...
In DejaNews you will find discussions
on topic for clpm & the CGI group
regarding Randomness and some
code which may help you.
HTH,
Sneex :-)
------------------------------
Date: Fri, 10 Apr 1998 12:48:23 GMT
From: henlif@elsfl.com (Henry Lifton)
Subject: Relational Searching
Message-Id: <6gl4or$3ms$1@usenet50.supernews.com>
I have done searching in flat file databases before, but now I have a database
with 2 tables with a one to many relationship.
I need to search on 1 field in one and on 3 fields in the other, then the
records that match those fields will be displayed.
Can this be done, and if you would be so kind give me a small example.
Thanks
Henry Lifton
------------------------------
Date: Fri, 10 Apr 1998 11:35:28 +0200
From: Olof Oberg <millNO@SPAMludd.luth.se>
Subject: Re: RMS should be invited to O'Reilly's "Free Software Summit"
Message-Id: <352DE7E0.11FC26C6@SPAMludd.luth.se>
> >> Hmm. If RMS does not qualify, then maybe Bill Gates is invited
> >> (because IE is a freeware).
>
> ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> >No it is not. You are mixing "free" and "free".
Well throughout the press release they are using the term 'freeware'
which I atleast defines as a matter of price. I.e. freeware is
not necessarily free software - as MSIE shows.
/mill
--
#############################################################
# millNO@SPAMludd.luth.se # http://pedgr571.sn.umu.se/~mill #
#############################################################
------------------------------
Date: 10 Apr 1998 10:00:56 GMT
From: Stefaan.Eeckels@ecc.lu (Stefaan A Eeckels)
Subject: Re: RMS should be invited to O'Reilly's "Free Software Summit"
Message-Id: <6gkqko$fl8$1@justus.ecc.lu>
[This will be my last post on this matter]
In article <6gjem4$f61$1@mathserv.mps.ohio-state.edu>,
ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> [A complimentary Cc of this posting was sent to Stefaan A Eeckels
> <Stefaan.Eeckels@ecc.lu>],
> who wrote in article <6giid7$2j0$1@justus.ecc.lu>:
>
>> Think about this - would you rather have GPL'd software maintained
>> and serviced by programmers, or Microsoft bloatware with regular,
>> expensive, incompatible updates, maintained and serviced by the
>> cheapest people MS can employ in their 'Customer Service'
>> department?
>
> People who resolve to use arguments like this one show they are not up
> to the argument. I will prefer AL and BSD-L to both situations.
What I meant to say is that with GPL'd software, you can sell
services that require decent programming skills, and that use
computers the proper way (like adapting the program to suit
the user's needs rather than vice-versa). With Open Source
software, this is possible. With proprietary software, the
only type of service that's left is the mind-numbing helpdesk
variety.
As you cast doubt on my ability to contribute to the argument,
let me indulge in a little anecdote:
Back in 1993, I discovered a problem with SCO V3.2's handling
of volumes it mounted through NFS from a SunOS box.
It was quite weird - files smaller than 8K gave no problems,
but larger ones could not be opened. The SCO box acted as
if the NFS server were down. I traced the packets on the
network, wrote a couple of programs to demonstrate the bug,
and submitted that to Olivetti (our vendor). They didn't have
a clue, and submitted the problem to SCO. I've not heard from
them since ;-). I fixed the problem by mounting the SCO volume
on the SunOS box, and since 1995 the problem has gone away
together with the SCO machine.
I'm quite sure that would never happen with a Linux box.
Capisce?
--
Stefaan
--
PGP key available from PGP key servers (http://www.pgp.net/pgpnet/)
___________________________________________________________________
"Don't worry about people stealing your ideas. If your ideas
are any good, you'll have to ram them down people's throats."
-- Howard Aiken
------------------------------
Date: Fri, 10 Apr 1998 01:15:57 -0700
From: Larry Rosler <lr@hpl.hp.com>
To: Zach Bagnall <zbweb@hotmail.com>
Subject: Re: rounding and precision
Message-Id: <352DD53D.BB57C0A6@hpl.hp.com>
Zach Bagnall wrote:
>
> Hi all,
>
> I'm having some trouble with rounding in perl.
>
> $y = 7;
> $m = 4 ** $y;
> print $m**(1/$y) - int($m**(1/$y));
>
> Why does this print 1 instead of 0? Is 1/7 irrational?
> How can I accurately check to see if $m**(1/$y) is an integer?
>
> Zach.
This is not a Perl question, but a general question of floating-point
computation using finite-length representations in real computers.
The issue is not whether 1/7 is irrational (it is rational by definition
-- it can be expressed exactly as the ratio of two integers, where the
denominator is not 0). The issue isn't even whether it can be
represented "exactly" in a finite-length binary representation (it
cannot), though that would sometimes lead to an "exact" root. The issue
is whether the computation that generates the power function (1/7 in
this case), which conceptually involves computing logarithms, yields an
"exact" integer.
I quote "exact" in each of the above sentences because for
floating-point representations (which are inescapable in this kind of
computation in general) there really is no such thing as an integer.
All you know is that the result of a floating-point calculation that
*looks like* an integer is within one half of the value of the least
significant bit of the representation of an integer.
So much for theory. To see what to do about this problem, compare the
following:
printf "%.20g %.20g\n", (4 ** 7) ** (1/7), 4;
My computer gives: 3.9999999999999996 4
though the same computation on a machine with a different floating-point
representation might vary. You *could* use some method like this to
"accurately check to see if $m**(1/$y) is an integer" but as I've
indicated above, it wouldn't prove a thing!
Please note that the view I've expressed here is not universally held,
particularly not by Velvel Kahan, godfather of the IEEE 754
floating-point standard. At the risk of misquoting lengthy discussions
many years ago, I can only say that the other view is that if a
calculation carried out to infinite precision (i.e., a mathematical
abstraction) yields an "integer" result, then the corresponding
floating-point calculation must yield the same result. Sometimes this
is fairly easy [(3.0 ** 2 + 4.0 ** 2) ** 1/2 == 5], sometimes it's not
[(4.0 ** 7.0) ** 1/7 != 4]. I claim that when it comes out "right" it's
a coincidence (hence mathematical identities cannot be relied on using
finite floating-point calculations). But I "lost" the theoretical
argument (but not the practical result, as you have seen).
Sorry for such a lengthy response to such a short question, but you
scratched an old wound!
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: 10 Apr 98 09:01:44 GMT
From: harrison@pixi.com (Robert F. Harrison)
Subject: Re: Week of Month
Message-Id: <slrn6irntr.stg.harrison@localhost.localdomain>
On Thu, 09 Apr 1998 I R A Aggie <fl_aggie@thepentagon.com> wrote:
>
> Hmmm...if you know the day of the week (DOTW) for the first, you can
> figure out what the following Sunday's numeric value is. Once you know
> the Sundays, then everything prior to that first Sunday is in week one,
> the days of $sunday[1]+6; is in week two, $sunday[2]+6 is week 3,
> $sunday[3]+6 is week 4, and $sunday[4]+6 {less than or equal to
> (28|29|30|31)}.
>
> Twould appear that there are 4 Sundays in every month, with most months
> having days spread out over 5 weeks. The only exception is a non-leap
> year February that starts on a Sunday -- 4 weeks exactly.
>
> There's a basic algorithm. I'll leave it to someone more motivated to
> code it up...
Having nothing better to do on a very wet and windy night I thought
I'd take a crack at it. It's probably not portable as it uses
Date::Manip (the UnixDate parts), does no error checking for things
like (13/32/-0001) - but then neither does a pencil, is slow, not
particularly clever, and so forth. In addition, I paid no attention
to which empire adopted what calendar in some other year of someone else's
calendar.
The one gotcha I found was that I'm used to GNU's 'data' which returns
the day of the week as (0-6) and (Sunday...Saturday). UnixDate (from
DateParse's Date::Manip), uses (1-7) and (Monday...Sunday). I never
thought of Sunday as being part of the previous week, but it's
probably just because I tend to think of indexes as beginning with
zero and Sunday, being a day of rest for me, needs no added value. :-)
Naturally I didn't find it till I was ready to post the code. It
seems to work now though. If there are any logical errors in it, it's
just as well I don't code for a living. If there are lot's of errors
in it, I'll complain to my ISP about someone forging my posts to clpm.
Here 'tis then --- oops, forgot to mention, with my apologies to the
rest of the world, it want month/day/year as it's input date format
instead of the day/month/year that is used elsewhere. What can I say?
I'm posting from the most remote island chain in the world
(distance-wise). If you wish to complain, you'll have to come out here
and do it to my face. I promise you'll have a good time.
#!/usr/bin/perl -w
use integer;
use Date::Manip;
use strict 'vars';
my $date = $ARGV[0];
my @longday = qw( Monday Tuesday Wednesday Thursday Friday Saturday Sunday );
my @weekname = qw( 1st 2nd 3rd 4th 5th );
my $weekday = UnixDate($date,"%w") - 1;
my $monthday = UnixDate($date, "%d");
my $weeknumber = $monthday/7;
my $firstday = $weekday - (($monthday % 7) - 1);
my $weekofmonth = $weekname[$weeknumber];
my $nameofday = $longday[$weekday];
my $nameof1st = $longday[$firstday];
print "It's $nameofday in the $weekofmonth week of the month.\n";
print "The 1st day of the month was a $nameof1st.\n";
--
rfh harrison@pixi.com
It's not the middle of nowhere, but if the sealevel rises...
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2289
**************************************