[19157] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1352 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 22 14:06:15 2001

Date: Sun, 22 Jul 2001 11:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <995825111-v10-i1352@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 22 Jul 2001     Volume: 10 Number: 1352

Today's topics:
    Re: Any perl module for XML Explorer tree display/edit? (sriram)
    Re: Appending to string in array <gnarinn@hotmail.com>
        Apple Quicktime Module <foo@northwestern.edu>
    Re: Collin hates subject lines. <collin@crosslink.net>
    Re: Collin hates subject lines. <collin@crosslink.net>
    Re: Collin hates subject lines. <collin@crosslink.net>
    Re: Conversion of month number to month name <ilya@martynov.org>
        Count of chacracters printed... <REMOVE_TO_REPLY.andyk@gliderpilot.net>
    Re: Count of chacracters printed... <pne-news-20010722@newton.digitalspace.net>
    Re: Count of chacracters printed... <REMOVE_TO_REPLY.andyk@gliderpilot.net>
    Re: Count of chacracters printed... <gnarinn@hotmail.com>
    Re: Count of chacracters printed... <pne-news-20010722@newton.digitalspace.net>
    Re: Count of chacracters printed... <godzilla@stomp.stomp.tokyo>
    Re: Email-address encoding <pne-news-20010722@newton.digitalspace.net>
    Re: Email-address encoding <bjoern@hoehrmann.de>
        FAQ: Why am I getting long decimals (eg, 19.94999999999 <faq@denver.pm.org>
    Re: How to supply modules with your software. <patelnavin@icenet.net>
    Re: How to supply modules with your software. <newspost@coppit.org>
    Re: How to supply modules with your software. <newspost@coppit.org>
        Purify-clean Perl for Solaris? (Jonathan Epstein)
    Re: Repetitive if statements (Alexis Machin)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Jul 2001 03:10:48 -0700
From: s_swami@yahoo.com (sriram)
Subject: Re: Any perl module for XML Explorer tree display/edit?
Message-Id: <c95b1060.0107220210.78e0965c@posting.google.com>

"M.L." <mel2000@hotmaildot.com> wrote in message news:<9j6v8s$mltff$1@ID-19545.news.dfncis.de>...
> I'm a newbie to XML currently reading up on various Perl modules to
> manipulate XML. My first goal is to find a module that can easily slurp an
> XML tree into a hash, and then back to an XML tree. With all the
> possibilities, I'm having trouble making up my mind.
> 
> After that task my greatest concern will be displaying and modifying the
> tree. Ideally, I would like to:
> 
> 1. Convert my spreadsheet-like database to an expanding/collapsing XML
> folder tree resembling that of Windows Explorer
> 
> 2. Tree display should collapse to 1 folder by default (stylesheet needed?)
> 
> 3. User must be able to add new record(s) to top of folder tree just as in
> Explorer
> 
> 4. User must be allowed to add new tag(s) to each record, but since each
> record is symmetrical, each new tag must be added to all records/folders in
> the tree.
> 
> I'd like to know if there is a Perl or Javascript module that can do most of
> what I am asking for as far as displaying and modifying the XML tree (as
> well as slurping/restoring).
> 
> Thanks

I think the best way is XML::Simple module. Please checkout the http://www.cpan.org

Thanks!!
--Sriram.


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

Date: Sun, 22 Jul 2001 15:29:03 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Appending to string in array
Message-Id: <995815743.570383518002927.gnarinn@hotmail.com>

In article <Pine.A41.4.33.0107211615190.145464-100000@dante59.u.washington.edu>,
Brian D. Green <greenbd@u.washington.edu> wrote:
>
>I'm now trying to write a script for my legislative simulation that allows
>users to add themselves as co-sponsors to a bill. It should read from the
>flat-file database where the bill information is stored, go to the line
>for the appropriate bill, and append their username and a pipe to the end
>of it. Here's what I've tried doing, but it just prints a lengthy error
>message into my data file instead of the username.
>

why not tell us exactly what error message you get?
we might not be in the mood to copy your code into a script,
put it into a cgi-bin directory, create the html file containing a form
that calls it, and test it , just to see the errors.
(ok, i know about offline execution and CGI.pm...)

>#!/usr/local/bin/perl -w

use strict;

>use CGI qw/:standard/;
>use CGI::Carp qw(fatalsToBrowser);
>print header;
>
>$number = param('number');
>$billtype = param('billtype');
>$netid = $ENV{'REMOTE_USER'};
>
>open (ADD_ME, ">>$billtype.out");

open (ADD_ME, ">>$billtype.out") or die "oops: $!";

>@data = <ADD_ME>;

here you are reading from a file opened for appending.

>
>foreach $line (@data) {
>	if ($line =~ /^$number\|/) {
>	$added = "$line";
>	$line = "";
>	print "$added$netid|";

do you mean:
  print ADD_ME "$added$netid|";
? even so, what about the lines that do not mach $number?

>	}
>}


>close (ADD_ME);
>
>What am I doing wrong, and how should I correct it? Thanks for your help!
what you are doing wrong, is not debugging your code

gnari


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

Date: Sat, 21 Jul 2001 17:03:25 -0500
From: "Jason Jenkins" <foo@northwestern.edu>
Subject: Apple Quicktime Module
Message-Id: <9jcse8$4tp$1@news.acns.nwu.edu>

I am just curious if there is a quicktime module, and if possible where this
could be obtained?








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

Date: Sun, 22 Jul 2001 11:09:46 -0400
From: "Collin E Borrlewyn" <collin@crosslink.net>
Subject: Re: Collin hates subject lines.
Message-Id: <3b5aec2f$0$25297@dingus.crosslink.net>


"John W. Krahn" <krahnj@acm.org> wrote in message
news:3B5A0226.678B60EE@acm.org...
> Collin E Borrlewyn wrote:
> >
> > "John W. Krahn" <krahnj@acm.org> wrote in message
> > news:3B59342E.1944EAC4@acm.org...
> > > Collin E Borrlewyn wrote:
> > > >
> > > > I'm writing a signup script for part of a larger message board.
> > Everything
> > > > else works, but I've been having trouble with preferences. I've
tracked
> > the
> > > > problem down to the following subroutine. (I don't know if the
> > indentation
> > > > will hold.)
> > > >
> > > > sub update_info(){
> >
> > >                  ^^
> > > You're saying you don't want to accept any arguments so @_ will be
empty
> > > (depending on how you call the sub.)
> >
> > Forgive my ignorance, but I don't follow.
> >
> > > sub update_info {
> > >     my ( $id, $field, $value ) = @_;
> >
> > Is there a good reason to do this? Apart from (perhaps) readability, I
am
> > unaware of an advantage.
>
> I can't count the number of times I've gone back to code I've written
> months or years ago (before I knew better) and tried to figure out WTF
> the code was doing. Descriptive variable names and limiting the scope of
> variables is very important in maintaining code over a long period of
> time.

I simply include a thorough description in comments about what exactly is
going on.  It's a bit trickier, but has the advantage of looking neater and
allowing me to talk to myself, an activity which I quite enjoy.

>
> > >     use Fcntl ':flock'; # import LOCK_* constants
> > >     open DATA,"< $userdir/$id" or return 0;
> > >     flock DATA, LOCK_EX unless $^O =~ /Win/;
> > >     my ( $data, @sig ) = <DATA>;
> > >     close DATA;
> > >
> > >     $data =~ s/$field\*(\S+)/$field*$value/;
> >
> > That's very nice, but it wont work for my purposes. First, it wont let
me
> > update the signature, which is stored with no label.
>
> Your original post didn't update the signature but it's easy enough to
> do:
>
> sub update_info {
>     my ( $id, $field, $value, @newsig ) = @_;
> ...
> @sig = @newsig if @newsig;

Actually, due to the way I find the sig elsewhere it wouldn't be sent as an
array, so, "@sig = split(/\n/,$newsig) if $newsig;" would be better.

> > Second, it doesn't let
> > people use spaces in their names. s/$field\*([^\t]+)/$field*$value/
would
> > fix the second but not the first problem.
> >
> > I was more interested in why it wasn't working than how to make it work.
I
> > can make it work by doing it differently, but the fact that this didn't
work
> > when it should have is annoying me.
>
> You can do it any way you want, I was just offering some suggestions.
> :-)

And I appreciate them. My second way was not as good as my third way, which
was based on your suggestion.


 ~Collin E Borrlewyn
  ~ END THE TYRANNY. VOTE 'DISEMBODIED MONKEY HEAD' FOR PRESIDENT.




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

Date: Sun, 22 Jul 2001 11:09:49 -0400
From: "Collin E Borrlewyn" <collin@crosslink.net>
Subject: Re: Collin hates subject lines.
Message-Id: <3b5aec32$0$25297@dingus.crosslink.net>


"Michael Budash" <mbudash@sonic.net> wrote in message
news:mbudash-C45A2C.08514221072001@news.sonic.net...
> In article <3b58f78b$0$23492@dingus.crosslink.net>, "Collin E
> Borrlewyn" <collin@crosslink.net> wrote:
>
> >         $data{$_[1]} = $data{$_[2]}; # Updates the element
>
> i'm not sure about the other posters' comments about prototyping, but
> based on your requirements, the above line should be:
>
> $data{$_[1]} = $_[2]; # Updates the element

Holy saint Farheim's flaming pants, I am an idiot on a scale scarcely
imagined in my own worst nightmares! Not only did I MAKE such a ghastly
mistake, but I didn't instantly see it when trying to find what was wrong,
even knowing that that was the exactly line on which the problem was
probably located.

I can not begin to berate myself enough for this, so i don't think I shall
even attempt it. So, I will close by apologizing to the universe at large,
and to Simon the rabbit from Michagen, BECAUSE SIMON DESERVES IT.

> hth-
> --
> Michael Budash ~~~~~~~~~~ mbudash@sonic.net


 ~Collin E Borrlewyn
  ~ END THE TYRANNY. VOTE 'DISEMBODIED MONKEY HEAD' FOR PRESIDENT.




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

Date: Sun, 22 Jul 2001 11:23:58 -0400
From: "Collin E Borrlewyn" <collin@crosslink.net>
Subject: Re: Collin hates subject lines.
Message-Id: <3b5aef83$0$25297@dingus.crosslink.net>


"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:9jcqoq$a0u$3@bob.news.rcn.net...
> Collin E Borrlewyn <collin@crosslink.net> wrote:
> >         open(DATA,"$userdir/$_[0]") || return 0;
> >         flock(DATA,2) unless $^O =~ /Win/;
> >         my($data,@sig) = <DATA>;
> >         close(DATA);
> >         my @data = split(/\t/,$data);
> >         chomp($data);
>
> [snip transformations]
>
> >         open(DATA,">$userdir/$_[0]") || return 0;
> >         flock(DATA,2) unless $^O =~ /Win/;
> >         print DATA $out."\n".$data{'SIG'};
> >         close(DATA) || return 0;
>
> Nobody else in this thread has yet commented on the fact that your locking
> is useless.  In between the time you read the file and write it back, it's
> unlocked and another process can grab it.

I know. This has caused my a fair amount of trouble.

> You need to open the file for
> read/write, lock it, read it, do your transformations, truncate the file,
> write it and only *then* close it.

Yes, well I have experimented (and looked at what documentation I could find
by various google searches and perldoc) and I have yet to figure out how to
actually DO this 'keeping open for reading and writing'. My results have
always been rather strange, and so (until I figure it out) I've been relying
on what I know works, as poor as it may be.

>
> You should use constants imported from Fcntl rather than magic numbers.

Until yesterday I didn't know Fcntl existed, and I'm still not sure what it
is (though finding out is next on my agenda).

> flock() *is* implemented on Windows NT and 2000, just not on 95/98/ME.
> Since multi-user programs are more likely to be run on the former than the
> latter, you need a better test of flock()'s availabilty; see recent
> threads for reliable ways to do it.

I don't use Windows2000, nor am I likely to. I also do not plan to
distribute the script (not for a long time, not till it's sufficiently
decent, maybe not at all). The exclusion of windows is so I may test it on
my Win98 machine, (which apparently doesn't like flock()) and upload it
right away without needing to re-edit it. It was never the plan to actually
*run* it from windows.



 ~Collin E Borrlewyn
  ~ END THE TYRANNY. VOTE 'DISEMBODIED MONKEY HEAD' FOR PRESIDENT.




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

Date: 22 Jul 2001 14:20:58 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Conversion of month number to month name
Message-Id: <87wv51w9h1.fsf@abra.ru>


PN> On 22 Jul 2001 12:37:57 +0400, Ilya Martynov <ilya@martynov.org> wrote:
>> How can I do conversion of month number to month name that honors
>> locale settings on Unix compatible platforms?

PN> POSIX::strftime, perhaps?

Thanx. It works.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Sun, 22 Jul 2001 12:32:10 +0100
From: "Andy Kirkland" <REMOVE_TO_REPLY.andyk@gliderpilot.net>
Subject: Count of chacracters printed...
Message-Id: <9jedds$ndke7$1@ID-49798.news.dfncis.de>

I'm trying to create a script that logs the output from my CGI scripts, and
want to be able to see the number of bytes transfered (ie printed from -
print "<HTML>\n" etc.).  Since it is a CGI generated script
$ENV{'CONTENT_LENGTH'} is not available.

Anyone got any ideas, considering the fact I don't want to rewrite all my
CGI scripts to be different from print "Info..." to anything else. What I
want is a function that simply displays the bytes printed.

Many thanks,

Andy




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

Date: Sun, 22 Jul 2001 17:53:45 +0200
From: Philip Newton <pne-news-20010722@newton.digitalspace.net>
Subject: Re: Count of chacracters printed...
Message-Id: <vhtlltcil1euffq3nisr3plfj9h8is3cfp@4ax.com>

On Sun, 22 Jul 2001 12:32:10 +0100, "Andy Kirkland"
<REMOVE_TO_REPLY.andyk@gliderpilot.net> wrote:

> I'm trying to create a script that logs the output from my CGI scripts,

How do you want to do that? Call the script via HTTP and read the number
of characters printed? Or somehow snoop the CGI interface while the
script is running? Or grovel over the source code and guess how many
characters will be printed?

> and want to be able to see the number of bytes transfered (ie printed
> from - print "<HTML>\n" etc.).

The number of bytes returned in an answer may be available from the web
server logs.

> Since it is a CGI generated script $ENV{'CONTENT_LENGTH'} is not
> available.

$ENV{'CONTENT_LENGTH'} in which environment? That sounds like a CGI
variable, which will be defined if the script querying
$ENV{'CONTENT_LENGTH'} is a CGI script. I thought your script wanted to
log output actively rather than passively wait to be called.

> Anyone got any ideas, considering the fact I don't want to rewrite all
> my CGI scripts to be different from print "Info..." to anything else.
> What I want is a function that simply displays the bytes printed.

Where would you put the function? Outside of the script probably won't
work (unless you call your script via HTTP and read the number of
characters returned), and inside the script contradicts your statement
"I don't want to rewrite my CGI scripts".

I'm confused.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 22 Jul 2001 17:04:43 +0100
From: "Andy Kirkland" <REMOVE_TO_REPLY.andyk@gliderpilot.net>
Subject: Re: Count of chacracters printed...
Message-Id: <9jetf2$ncrhq$1@ID-49798.news.dfncis.de>

What I want essentially is to know how many characters my CGI script has
printed at any given point (ie: the end of the script) ie: how many
characters "print" has outputted...

Is this possible?

Andy

Philip Newton <pne-news-20010722@newton.digitalspace.net> wrote in message
news:vhtlltcil1euffq3nisr3plfj9h8is3cfp@4ax.com...
> On Sun, 22 Jul 2001 12:32:10 +0100, "Andy Kirkland"
> <REMOVE_TO_REPLY.andyk@gliderpilot.net> wrote:
>
> > I'm trying to create a script that logs the output from my CGI scripts,
>
> How do you want to do that? Call the script via HTTP and read the number
> of characters printed? Or somehow snoop the CGI interface while the
> script is running? Or grovel over the source code and guess how many
> characters will be printed?
>
> > and want to be able to see the number of bytes transfered (ie printed
> > from - print "<HTML>\n" etc.).
>
> The number of bytes returned in an answer may be available from the web
> server logs.
>
> > Since it is a CGI generated script $ENV{'CONTENT_LENGTH'} is not
> > available.
>
> $ENV{'CONTENT_LENGTH'} in which environment? That sounds like a CGI
> variable, which will be defined if the script querying
> $ENV{'CONTENT_LENGTH'} is a CGI script. I thought your script wanted to
> log output actively rather than passively wait to be called.
>
> > Anyone got any ideas, considering the fact I don't want to rewrite all
> > my CGI scripts to be different from print "Info..." to anything else.
> > What I want is a function that simply displays the bytes printed.
>
> Where would you put the function? Outside of the script probably won't
> work (unless you call your script via HTTP and read the number of
> characters returned), and inside the script contradicts your statement
> "I don't want to rewrite my CGI scripts".
>
> I'm confused.
>
> Cheers,
> Philip
> --
> Philip Newton <nospam.newton@gmx.li>
> That really is my address; no need to remove anything to reply.
> If you're not part of the solution, you're part of the precipitate.




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

Date: Sun, 22 Jul 2001 15:43:44 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Count of chacracters printed...
Message-Id: <995816624.920648517552763.gnarinn@hotmail.com>

In article <9jedds$ndke7$1@ID-49798.news.dfncis.de>,
Andy Kirkland <REMOVE_TO_REPLY.andyk@gliderpilot.net> wrote:
>I'm trying to create a script that logs the output from my CGI scripts, and
>want to be able to see the number of bytes transfered (ie printed from -
>print "<HTML>\n" etc.).  Since it is a CGI generated script
>$ENV{'CONTENT_LENGTH'} is not available.
>
why not just read the webserver access logs?

much easier than rewriting all your cgis

gnari


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

Date: Sun, 22 Jul 2001 18:25:34 +0200
From: Philip Newton <pne-news-20010722@newton.digitalspace.net>
Subject: Re: Count of chacracters printed...
Message-Id: <ghvlltoj2vtiifd9d01iitrdjv51kdrql6@4ax.com>

On Sun, 22 Jul 2001 17:04:43 +0100, "Andy Kirkland"
<REMOVE_TO_REPLY.andyk@gliderpilot.net> wrote:

> What I want essentially is to know how many characters my CGI script has
> printed at any given point (ie: the end of the script) ie: how many
> characters "print" has outputted...

Only characters from "print"?

> Is this possible?

I don't think so -- at least, not without something like a tied
filehandle or a replacement for 'print'. If you look in the web server
log, you'll probably find the number of bytes transmitted, but that
counts everything sent over the stream. So if you call an external
program that writes to STDOUT, that program's bytes would also be
counted.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 22 Jul 2001 09:34:58 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Count of chacracters printed...
Message-Id: <3B5B00B2.9BDB3204@stomp.stomp.tokyo>

Andy Kirkland wrote:
 
> I'm trying to create a script that logs the output from my CGI scripts, and
> want to be able to see the number of bytes transfered (ie printed from -
> print "<HTML>\n" etc.).  Since it is a CGI generated script
> $ENV{'CONTENT_LENGTH'} is not available.
 
> Anyone got any ideas, considering the fact I don't want to rewrite all my
> CGI scripts to be different from print "Info..." to anything else. What I
> want is a function that simply displays the bytes printed.
 

You need to clarify if you want a printed character count
or transmitted byte count. These two are not the same.

A printed character count is not possible without adding
code to your existing script. Easy enough to do by creating
a tally of all printed characters using length () then
appending your desired information to a custom log file.

A byte transmitted count is equally easy and requires no
modification to a script. This can be accomplished by use
of a custom server log which targets your selected scripts.
Technical information on how this is done for Apache is
available here:

http://httpd.apache.org/docs/mod/mod_log_config.html#customlog


Godzilla!


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

Date: Sun, 22 Jul 2001 17:49:42 +0200
From: Philip Newton <pne-news-20010722@newton.digitalspace.net>
Subject: Re: Email-address encoding
Message-Id: <15tlltci301vc3pt8gg15pnlb38atfoo8k@4ax.com>

On Sun, 22 Jul 2001 11:49:36 +0100, "Tim Lauterborn"
<email@timlauterborn.de> wrote:

> You are only allowed to use 7 bit characters in emailaddresses so that
> Netscape and Outlook code them in iso-8859-1 format:

I think you're mixed up about terminology. iso-8859-1 is the charset
advertised, but the encoding is (I believe) called MIME 'Q' encoding,
and is derived from quoted-printable.

> Original string: zriuwe$%$&/§%$/&
> Coded string:  =?iso-8859-1?Q?zriuwe=24=25=24=26=2F=A7=25=24=2F=26?=

MIME::QuotedPrint can generated QP encoding, but I'm not sure about the
'Q' encoding used in headers. (There's also a 'B' encoding which derived
from base64 encoding.)

Hmm... <looks around CPAN> I think you might want the MIME-tools
package; specifically, the MIME::Words module and its encode_mimeword
subroutine looks promising. You can specify an encoding ('Q' or 'B';
default is 'Q') and a charset (default is 'iso-8859-1'). So you should
be able to go with the defaults.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 22 Jul 2001 18:09:37 +0200
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: Email-address encoding
Message-Id: <3b5beed2.4880958@news.bjoern.hoehrmann.de>

* Tim Lauterborn wrote in comp.lang.perl.misc:
>I send emails using sendmail. You are only allowed to use 7 bit characters
>in emailaddresses so that Netscape and Outlook code them in iso-8859-1
>format:
>Original string: zriuwe$%$&/§%$/&
>Coded string:  =?iso-8859-1?Q?zriuwe=24=25=24=26=2F=A7=25=24=2F=26?=
>
>Does someone know a module or regular expression to convert a string to
>iso-8859-1?

That's not ISO-8859-1, that MIME Word encoding. Take a look at
MIME::Words and MIME::WordDecorder.
-- 
Björn Höhrmann { mailto:bjoern@hoehrmann.de } http://www.bjoernsworld.de
am Badedeich 7 } Telefon: +49(0)4667/981028 { http://bjoern.hoehrmann.de
25899 Dagebüll { PGP Pub. KeyID: 0xA4357E78 } http://www.learn.to/quote/


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

Date: Sun, 22 Jul 2001 12:16:59 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?
Message-Id: <%uz67.17$T3.171338752@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

    The infinite set that a mathematician thinks of as the real numbers can
    only be approximated on a computer, since the computer only has a finite
    number of bits to store an infinite number of, um, numbers.

    Internally, your computer represents floating-point numbers in binary.
    Floating-point numbers read in from a file or appearing as literals in
    your program are converted from their decimal floating-point
    representation (eg, 19.95) to an internal binary representation.

    However, 19.95 can't be precisely represented as a binary floating-point
    number, just like 1/3 can't be exactly represented as a decimal
    floating-point number. The computer's binary representation of 19.95,
    therefore, isn't exactly 19.95.

    When a floating-point number gets printed, the binary floating-point
    representation is converted back to decimal. These decimal numbers are
    displayed in either the format you specify with printf(), or the current
    output format for numbers. (See the section on "$#" in the perlvar
    manpage if you use print. "$#" has a different default value in Perl5
    than it did in Perl4. Changing "$#" yourself is deprecated.)

    This affects all computer languages that represent decimal
    floating-point numbers in binary, not just Perl. Perl provides
    arbitrary-precision decimal numbers with the Math::BigFloat module (part
    of the standard Perl distribution), but mathematical operations are
    consequently slower.

    To get rid of the superfluous digits, just use a format (eg,
    "printf("%.2f", 19.95)") to get the required precision. See the section
    on "Floating-point Arithmetic" in the perlop manpage.

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           04.01
-- 
    This space intentionally left blank


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

Date: Sun, 22 Jul 2001 17:53:48 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: Re: How to supply modules with your software.
Message-Id: <9jegh4$n475n$1@ID-93885.news.dfncis.de>

(snipped)

> I never write distribution scripts which require
> a module for operation. This is a simple solution
> requiring nothing more than decent programming
> skills and sufficient personal pride in your work
> to motivate you to write real programs rather
> than copy and paste baling wire scripts which
> rely upon the programming skills of others.

What do you think modules are for?




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

Date: Sun, 22 Jul 2001 10:54:37 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: How to supply modules with your software.
Message-Id: <3B5AE92D.8080905@coppit.org>

Godzilla! wrote:

> I never write distribution scripts which require
> a module for operation. This is a simple solution
> requiring nothing more than decent programming
> skills and sufficient personal pride in your work
> to motivate you to write real programs rather
> than copy and paste baling wire scripts which
> rely upon the programming skills of others.

Please do not advocate this position. If there's *anything* the endeavor 
of engineering has taught us, it's that it is *impossible* to build real 
systems having reasonable size, reliability, and understandability 
characteristics without taking advantage of modularity.

If you think I'm wrong, I challenge you to write down all the concerns 
you think are relevant to the simple task of locking a file. Then go 
look at LockFile::Simple and see if you thought of everything that could 
go wrong. Then think about the issues involved in computing the number 
of days between two arbitrary dates, and go look at Date::Manip.

If you can accurately anticipate all the exceptional conditions, *and* 
you could implement them all correctly on the first try, great. You're 
Godzilla stomping on the problems of software development. But for us 
mortals, we have to rely on the capabilities of those that have 
implemented, tested, debugged, documented, and evolved solutions. Please 
don't ask us to be that good on the first try.

David



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

Date: Sun, 22 Jul 2001 11:01:27 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: How to supply modules with your software.
Message-Id: <3B5AEAC7.6030007@coppit.org>

Aman Patel wrote:

> I wanted to know any fool proof way to supplying modules...

Hi Aman,

Generally I think it's a bad idea to distribute external modules with 
your own module (but see below). The reason is that it locks you into 
particular versions, and makes it more difficult for the module author 
to distribute new versions. It's better to distribute your own modules, 
then put your module requirements in PREREQ_PM of Makefile.PL. Then put 
instructions in your README that tell people how to use "perl -MCPAN -e 
shell" to install the necessary modules.

If you want to make it easier for people to grab all the necessary 
modules, create a Bundle and stick it on CPAN.

The only time I would consider distributing someone else's module is if 
their new version is not backwards compatible, and if they don't plan on 
making their module so.

David



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

Date: Sun, 22 Jul 2001 14:12:29 GMT
From: jepstein@helix.nih.gov (Jonathan Epstein)
Subject: Purify-clean Perl for Solaris?
Message-Id: <hbB67.104$Uf1.296899@mencken.net.nih.gov>

Hi,

I am working on a SWIG extension, and won't be really satisfied with it
until I try it with Purify.  I would like to use both (a) the best
platform and (b) the Perl release or pre-release, which will provide the
most Purify-clean starting point.

Of my available systems which could support Purify, my first choice is a
Solaris 7 system with a gcc compiler, but lacking the cc compiler.  Second
choice is an Irix 6.5 system where I have the commercial cc compiler, and
don't trust the behavior of gcc (based on past experience on this
particular system) and third choice is a Windoze 2000 machine with MS
Visual C++ and where it would be easy to install gcc et al as appropriate.

Buying the Solaris cc compiler in addition to Purify is also an option,
but not my first choice.  Not having to build Perl from source code would
also be nice.

The more important question for the Perl wizards is which release is
most appropriate, i.e. Purified.  I've seen this issue addressed in the
newsgroup archives, but don't know the current state of affairs.

Please let me know if I should redirect this to a Porters or Wizards group.

TIA,

- Jonathan


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

Date: Sun, 22 Jul 2001 14:47:15 GMT
From: a.m@myDesktop.somewhereOverTheRainbow.org.nospam (Alexis Machin)
Subject: Re: Repetitive if statements
Message-Id: <3b5ae4d8.189997578@news.freeserve.co.uk>

On Sat, 21 Jul 2001 16:06:48 -0700, "Brian D. Green" <greenbd@u.washington.edu>
wrote:

>On Sat, 21 Jul 2001, Godzilla! wrote:

[... more stupidity...]

>For the record, Alexis was right. I specified the image sizes to improve
>load time; the files are all less than 0.2K anyway. Thanks for
>contributing, though.

The funny thing is, idiots such as G and others I've encountered in other newsgroups
almost always have to pay to post anonymously to usenet after having their privilages
cut from any reputable isp. Services like supernews, alt.net etc, specialize in
providing these buffoons with an outlet, secure in the knowledge they can cower
behind said "services" rather liberal terms and conditions. Sort of like a sewerage
tank dumping its contents into a stream.

The sad thing is, all the morons posting rubbish into groups each think they're
original and witty, yet from my perspective at least, it just looks like some lonely
person attempting to belittle others to make their life seem less depressing...

The good thing is, filtering out everything from these "safe-houses" for morons will
make these little people go away! :-) (If only Agent could do it...)

-- 
Alexis Machin


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

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.  

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


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