[31313] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2558 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 18 06:09:48 2009

Date: Tue, 18 Aug 2009 03:09:05 -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           Tue, 18 Aug 2009     Volume: 11 Number: 2558

Today's topics:
    Re: end-of-line conventions sln@netherlands.com
    Re: log timestamp a script is used <derykus@gmail.com>
    Re: log timestamp a script is used <ben@morrow.me.uk>
        Posting Guidelines for comp.lang.perl.misc ($Revision:  tadmc@seesig.invalid
    Re: revisiting web development in Perl...where to start (Jamie)
    Re: revisiting web development in Perl...where to start (Jamie)
    Re: Rounding issue (Jens Thoms Toerring)
    Re: Rounding issue (Doug Miller)
    Re: Rounding issue sln@netherlands.com
    Re: Rounding issue <jurgenex@hotmail.com>
    Re: Rounding issue sln@netherlands.com
    Re: Rounding issue sln@netherlands.com
    Re: Rounding issue sln@netherlands.com
    Re: Social problems of Python doc [was Re: Python docs  <nat.k@gm.ml>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 17 Aug 2009 15:23:32 -0700
From: sln@netherlands.com
Subject: Re: end-of-line conventions
Message-Id: <qmjj85tbesqkcfnpms3pogh5gl8uf8t2mr@4ax.com>

On Sun, 16 Aug 2009 18:24:22 +0100, Ben Morrow <ben@morrow.me.uk> wrote:

>
>Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
>> In <h2qjl6-4ht2.ln1@osiris.mauzo.dyndns.org>, on 08/15/2009
>>    at 11:39 PM, Ben Morrow <ben@morrow.me.uk> said:
>> 
>> >"\n" can *never* mean "\015\012":
>> 
>> Are you a betting man.
>
>Not usually :).
>
>> >"\n" can *never* mean "\015\012": on Win32 it means "\012", just as on
>> >Unix. If "\n" was more than one byte/character (take your pick) long,
>> >practically everything would break. 
>> 
>> Wrong; \n is two bytes on DOS and OS/2, and AFAIK nothing breaks except
>> cgi.pm.
>
>No it's not, at least not as far as Perl is concerned. Files have CRLF
>line endings, but they are (by default) translated into LF line endings
>when the file is read. If you have a file containing
>
>    fooCRLF
>
>and you read a line with
>
>    open my $FOO, "<", "foo";
>    my $foo = <$FOO>;
>
>then $foo will be four bytes long, not five.
>
>> >AFAIK the only platforms where "\n" ne "\012" are Mac OS Classic and 
>> >the EBCDIC platforms, both of which are obsolete as far as Perl is 
>> >concerned.
>> 
>> When there's ongoing maintenance then it's a rather lively corpse.
>
>Perl is no longer maintained for Mac OS Classic or the EBCDIC platforms.
>I did not mean to imply they were obsolete for other purposes.
>
>Ben

Yes this is fairly standard ANSI translations.

This fopen api documentation, phrase sums it up:
"Carriage return–line feed (CR-LF) combinations are translated
 into a single line feed character on input.
 Line feed characters are translated into CR-LF combinations on output. "


Opening in text mode, translated is the default, and these things happen:

- On reads: CRLF are converted to LF's
- On writes: LF is converted to CRLF's
- EOL character is the LF
- binmode(STDOUT,':raw') is not good for viewing because the console does real \r and \n

Finally, there is no clear cut solution to the OP I don't believe.

If one platform can append CR's and another LF's as eol's, then it can't be
determined that these are seperate eol's. Of course, another comes along and
adds the CRLF pair as eol.

Either way, opening a file in ':raw' mode and doing your own eol
translations, would make this, by definition:  if /\015?\012?/ ++$linecnt,
invalid.

I guess there is the C fmode and setmode to read, turn on/off translations.
Unless there is a convergence of platform meanings that don't step on each
other when files are appeneded in translated mode (if it is supported), opening
a file un-translated and doing your own eol translation, would no seem to be
%100 reliable.

-sln

Raw Data:
  (18) = 54  d  a  57  a  a  d  d  58  65  64  66  d  d  59  d  a  5a
  (18) = T..W....Xedf..Y..Z

Writing translated text file
--------------------

Reading translated text file
--------------------
tran (18) = 54  d  a  57  a  a  d  d  58  65  64  66  d  d  59  d  a  5a
     (18) = T..W....Xedf..Y..Z
( 3) = T ( d a )
( 2) = W ( a )
( 1) = ( a )
(11) = ( d d ) Xedf ( d d ) Y ( d a )
( 1) = Z

Reading un-translated text file
--------------------
raw  (22) = 54  d  d  a  57  d  a  d  a  d  d  58  65  64  66  d  d  59  d  d  a  5a
     (22) = T ( d d a ) W ( d a d a d d ) Xedf ( d d ) Y ( d d a ) Z
     (22) = T...W......Xedf..Y...Z
( 4) = T ( d d a )
( 3) = W ( d a )
( 2) = ( d a )
(12) = ( d d ) Xedf ( d d ) Y ( d d a )
( 1) = Z

=============================================

Writing RAW text file
--------------------

Reading translated text file
--------------------
tran (16) = 54  a  57  a  a  d  d  58  65  64  66  d  d  59  a  5a
     (16) = T.W....Xedf..Y.Z
( 2) = T ( a )
( 2) = W ( a )
( 1) = ( a )
(10) = ( d d ) Xedf ( d d ) Y ( a )
( 1) = Z

Reading un-translated text file
--------------------
raw  (18) = 54  d  a  57  a  a  d  d  58  65  64  66  d  d  59  d  a  5a
     (18) = T ( d a ) W ( a a d d ) Xedf ( d d ) Y ( d a ) Z
     (18) = T..W....Xedf..Y..Z
( 3) = T ( d a )
( 2) = W ( a )
( 1) = ( a )
(11) = ( d d ) Xedf ( d d ) Y ( d a )
( 1) = Z




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

Date: Mon, 17 Aug 2009 17:43:42 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: log timestamp a script is used
Message-Id: <a70188b4-0414-46d2-ae99-4ee9ad858884@w6g2000yqw.googlegroups.com>

On Aug 17, 5:02=A0am, GU <gerhard_ulr...@yahoo.de> wrote:
> Hi,
>
> currently we've a lot of scripts, but don't know how often each one is
> used.
>
> To clean up those jumble of scripts i wanna log the timestamp a script
> is used.
>
> For that i like to do something like this:
> system "echo $0 `date` >> /tmp/script_used.log";
> but WITHOUT modifing each skript itself.
>
> i would imagine two ways:
> 1) set of environment to tell perl to do something like that (but
> which setting would do that?, alias would not work --> different users
> - different shells)
> 2) recompilation of perl (but i havn't compiled perl jet and don't
> know how to do that)
>
> Is there a way to do this?
>

One possibility:  save the actual perl executable off somewhere
and substitute a short C program that'd do the logging and then
just exec the saved perl.

(This should be fairly easy on Unix but may need some more tweaks
if other O/S's are in the fray).

--
Charles DeRykus




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

Date: Tue, 18 Aug 2009 02:17:09 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: log timestamp a script is used
Message-Id: <l1cpl6-6qq.ln1@osiris.mauzo.dyndns.org>


Quoth GU <gerhard_ulrike@yahoo.de>:
> 
> currently we've a lot of scripts, but don't know how often each one is
> used.
> 
> To clean up those jumble of scripts i wanna log the timestamp a script
> is used.
> 
> For that i like to do something like this:
> system "echo $0 `date` >> /tmp/script_used.log";
> but WITHOUT modifing each skript itself.

Another possibility has just occured to me, which I think I like best:
if you have or can build a perl with -Dusesitecustomize, you can put a
sitecustomize.pl file in an appropriate place and it will be run every
time perl starts up. This would be a good place to choose what to log
and where to log it. See "-f" in perldoc perlrun.

Ben



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

Date: Tue, 18 Aug 2009 02:18:57 -0500
From: tadmc@seesig.invalid
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
Message-Id: <goydnQXSacB8yBfXnZ2dnUVZ_omdnZ2d@giganews.com>

Outline
   Before posting to comp.lang.perl.misc
      Must
       - Check the Perl Frequently Asked Questions (FAQ)
       - Check the other standard Perl docs (*.pod)
      Really Really Should
       - Lurk for a while before posting
       - Search a Usenet archive
      If You Like
       - Check Other Resources
   Posting to comp.lang.perl.misc
      Is there a better place to ask your question?
       - Question should be about Perl, not about the application area
      How to participate (post) in the clpmisc community
       - Carefully choose the contents of your Subject header
       - Use an effective followup style
       - Speak Perl rather than English, when possible
       - Ask perl to help you
       - Do not re-type Perl code
       - Provide enough information
       - Do not provide too much information
       - Do not post binaries, HTML, or MIME
      Social faux pas to avoid
       - Asking a Frequently Asked Question
       - Asking a question easily answered by a cursory doc search
       - Asking for emailed answers
       - Beware of saying "doesn't work"
       - Sending a "stealth" Cc copy
      Be extra cautious when you get upset
       - Count to ten before composing a followup when you are upset
       - Count to ten after composing and before posting when you are upset
-----------------------------------------------------------------

Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
    This newsgroup, commonly called clpmisc, is a technical newsgroup
    intended to be used for discussion of Perl related issues (except job
    postings), whether it be comments or questions.

    As you would expect, clpmisc discussions are usually very technical in
    nature and there are conventions for conduct in technical newsgroups
    going somewhat beyond those in non-technical newsgroups.

    The article at:

        http://www.catb.org/~esr/faqs/smart-questions.html

    describes how to get answers from technical people in general.

    This article describes things that you should, and should not, do to
    increase your chances of getting an answer to your Perl question. It is
    available in POD, HTML and plain text formats at:

     http://www.rehabitation.com/clpmisc.shtml

    For more information about netiquette in general, see the "Netiquette
    Guidelines" at:

     http://andrew2.andrew.cmu.edu/rfc/rfc1855.html

    A note to newsgroup "regulars":

       Do not use these guidelines as a "license to flame" or other
       meanness. It is possible that a poster is unaware of things
       discussed here.  Give them the benefit of the doubt, and just
       help them learn how to post, rather than assume that they do 
       know and are being the "bad kind" of Lazy.

    A note about technical terms used here:

       In this document, we use words like "must" and "should" as
       they're used in technical conversation (such as you will
       encounter in this newsgroup). When we say that you *must* do
       something, we mean that if you don't do that something, then
       it's unlikely that you will benefit much from this group.
       We're not bossing you around; we're making the point without
       lots of words.

    Do *NOT* send email to the maintainer of these guidelines. It will be
    discarded unread. The guidelines belong to the newsgroup so all
    discussion should appear in the newsgroup. I am just the secretary that
    writes down the consensus of the group.

Before posting to comp.lang.perl.misc
  Must
    This section describes things that you *must* do before posting to
    clpmisc, in order to maximize your chances of getting meaningful replies
    to your inquiry and to avoid getting flamed for being lazy and trying to
    have others do your work.

    The perl distribution includes documentation that is copied to your hard
    drive when you install perl. Also installed is a program for looking
    things up in that (and other) documentation named 'perldoc'.

    You should either find out where the docs got installed on your system,
    or use perldoc to find them for you. Type "perldoc perldoc" to learn how
    to use perldoc itself. Type "perldoc perl" to start reading Perl's
    standard documentation.

    Check the Perl Frequently Asked Questions (FAQ)
        Checking the FAQ before posting is required in Big 8 newsgroups in
        general, there is nothing clpmisc-specific about this requirement.
        You are expected to do this in nearly all newsgroups.

        You can use the "-q" switch with perldoc to do a word search of the
        questions in the Perl FAQs.

    Check the other standard Perl docs (*.pod)
        The perl distribution comes with much more documentation than is
        available for most other newsgroups, so in clpmisc you should also
        see if you can find an answer in the other (non-FAQ) standard docs
        before posting.

    It is *not* required, or even expected, that you actually *read* all of
    Perl's standard docs, only that you spend a few minutes searching them
    before posting.

    Try doing a word-search in the standard docs for some words/phrases
    taken from your problem statement or from your very carefully worded
    "Subject:" header.

  Really Really Should
    This section describes things that you *really should* do before posting
    to clpmisc.

    Lurk for a while before posting
        This is very important and expected in all newsgroups. Lurking means
        to monitor a newsgroup for a period to become familiar with local
        customs. Each newsgroup has specific customs and rituals. Knowing
        these before you participate will help avoid embarrassing social
        situations. Consider yourself to be a foreigner at first!

    Search a Usenet archive
        There are tens of thousands of Perl programmers. It is very likely
        that your question has already been asked (and answered). See if you
        can find where it has already been answered.

        One such searchable archive is:

         http://groups.google.com/advanced_search

  If You Like
    This section describes things that you *can* do before posting to
    clpmisc.

    Check Other Resources
        You may want to check in books or on web sites to see if you can
        find the answer to your question.

        But you need to consider the source of such information: there are a
        lot of very poor Perl books and web sites, and several good ones
        too, of course.

Posting to comp.lang.perl.misc
    There can be 200 messages in clpmisc in a single day. Nobody is going to
    read every article. They must decide somehow which articles they are
    going to read, and which they will skip.

    Your post is in competition with 199 other posts. You need to "win"
    before a person who can help you will even read your question.

    These sections describe how you can help keep your article from being
    one of the "skipped" ones.

  Is there a better place to ask your question?
    Question should be about Perl, not about the application area
        It can be difficult to separate out where your problem really is,
        but you should make a conscious effort to post to the most
        applicable newsgroup. That is, after all, where you are the most
        likely to find the people who know how to answer your question.

        Being able to "partition" a problem is an essential skill for
        effectively troubleshooting programming problems. If you don't get
        that right, you end up looking for answers in the wrong places.

        It should be understood that you may not know that the root of your
        problem is not Perl-related (the two most frequent ones are CGI and
        Operating System related), so off-topic postings will happen from
        time to time. Be gracious when someone helps you find a better place
        to ask your question by pointing you to a more applicable newsgroup.

  How to participate (post) in the clpmisc community
    Carefully choose the contents of your Subject header
        You have 40 precious characters of Subject to win out and be one of
        the posts that gets read. Don't waste them. Take care while
        composing them, they are the key that opens the door to getting an
        answer.

        Spend them indicating what aspect of Perl others will find if they
        should decide to read your article.

        Do not spend them indicating "experience level" (guru, newbie...).

        Do not spend them pleading (please read, urgent, help!...).

        Do not spend them on non-Subjects (Perl question, one-word
        Subject...)

        For more information on choosing a Subject see "Choosing Good
        Subject Lines":

         http://www.cpan.org/authors/id/D/DM/DMR/subjects.post

        Part of the beauty of newsgroup dynamics, is that you can contribute
        to the community with your very first post! If your choice of
        Subject leads a fellow Perler to find the thread you are starting,
        then even asking a question helps us all.

    Use an effective followup style
        When composing a followup, quote only enough text to establish the
        context for the comments that you will add. Always indicate who
        wrote the quoted material. Never quote an entire article. Never
        quote a .signature (unless that is what you are commenting on).

        Intersperse your comments *following* each section of quoted text to
        which they relate. Unappreciated followup styles are referred to as
        "top-posting", "Jeopardy" (because the answer comes before the
        question), or "TOFU" (Text Over, Fullquote Under).

        Reversing the chronology of the dialog makes it much harder to
        understand (some folks won't even read it if written in that style).
        For more information on quoting style, see:

         http://web.presby.edu/~nnqadmin/nnq/nquote.html

    Speak Perl rather than English, when possible
        Perl is much more precise than natural language. Saying it in Perl
        instead will avoid misunderstanding your question or problem.

        Do not say: I have variable with "foo\tbar" in it.

        Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
        or I have $var = <DATA> (and show the data line).

    Ask perl to help you
        You can ask perl itself to help you find common programming mistakes
        by doing two things: enable warnings (perldoc warnings) and enable
        "strict"ures (perldoc strict).

        You should not bother the hundreds/thousands of readers of the
        newsgroup without first seeing if a machine can help you find your
        problem. It is demeaning to be asked to do the work of a machine. It
        will annoy the readers of your article.

        You can look up any of the messages that perl might issue to find
        out what the message means and how to resolve the potential mistake
        (perldoc perldiag). If you would like perl to look them up for you,
        you can put "use diagnostics;" near the top of your program.

    Do not re-type Perl code
        Use copy/paste or your editor's "import" function rather than
        attempting to type in your code. If you make a typo you will get
        followups about your typos instead of about the question you are
        trying to get answered.

    Provide enough information
        If you do the things in this item, you will have an Extremely Good
        chance of getting people to try and help you with your problem!
        These features are a really big bonus toward your question winning
        out over all of the other posts that you are competing with.

        First make a short (less than 20-30 lines) and *complete* program
        that illustrates the problem you are having. People should be able
        to run your program by copy/pasting the code from your article. (You
        will find that doing this step very often reveals your problem
        directly. Leading to an answer much more quickly and reliably than
        posting to Usenet.)

        Describe *precisely* the input to your program. Also provide example
        input data for your program. If you need to show file input, use the
        __DATA__ token (perldata.pod) to provide the file contents inside of
        your Perl program.

        Show the output (including the verbatim text of any messages) of
        your program.

        Describe how you want the output to be different from what you are
        getting.

        If you have no idea at all of how to code up your situation, be sure
        to at least describe the 2 things that you *do* know: input and
        desired output.

    Do not provide too much information
        Do not just post your entire program for debugging. Most especially
        do not post someone *else's* entire program.

    Do not post binaries, HTML, or MIME
        clpmisc is a text only newsgroup. If you have images or binaries
        that explain your question, put them in a publically accessible
        place (like a Web server) and provide a pointer to that location. If
        you include code, cut and paste it directly in the message body.
        Don't attach anything to the message. Don't post vcards or HTML.
        Many people (and even some Usenet servers) will automatically filter
        out such messages. Many people will not be able to easily read your
        post. Plain text is something everyone can read.

  Social faux pas to avoid
    The first two below are symptoms of lots of FAQ asking here in clpmisc.
    It happens so often that folks will assume that it is happening yet
    again. If you have looked but not found, or found but didn't understand
    the docs, say so in your article.

    Asking a Frequently Asked Question
        It should be understood that you may have missed the applicable FAQ
        when you checked, which is not a big deal. But if the Frequently
        Asked Question is worded similar to your question, folks will assume
        that you did not look at all. Don't become indignant at pointers to
        the FAQ, particularly if it solves your problem.

    Asking a question easily answered by a cursory doc search
        If folks think you have not even tried the obvious step of reading
        the docs applicable to your problem, they are likely to become
        annoyed.

        If you are flamed for not checking when you *did* check, then just
        shrug it off (and take the answer that you got).

    Asking for emailed answers
        Emailed answers benefit one person. Posted answers benefit the
        entire community. If folks can take the time to answer your
        question, then you can take the time to go get the answer in the
        same place where you asked the question.

        It is OK to ask for a *copy* of the answer to be emailed, but many
        will ignore such requests anyway. If you munge your address, you
        should never expect (or ask) to get email in response to a Usenet
        post.

        Ask the question here, get the answer here (maybe).

    Beware of saying "doesn't work"
        This is a "red flag" phrase. If you find yourself writing that,
        pause and see if you can't describe what is not working without
        saying "doesn't work". That is, describe how it is not what you
        want.

    Sending a "stealth" Cc copy
        A "stealth Cc" is when you both email and post a reply without
        indicating *in the body* that you are doing so.

  Be extra cautious when you get upset
    Count to ten before composing a followup when you are upset
        This is recommended in all Usenet newsgroups. Here in clpmisc, most
        flaming sub-threads are not about any feature of Perl at all! They
        are most often for what was seen as a breach of netiquette. If you
        have lurked for a bit, then you will know what is expected and won't
        make such posts in the first place.

        But if you get upset, wait a while before writing your followup. I
        recommend waiting at least 30 minutes.

    Count to ten after composing and before posting when you are upset
        After you have written your followup, wait *another* 30 minutes
        before committing yourself by posting it. You cannot take it back
        once it has been said.

AUTHOR
    Tad McClellan and many others on the comp.lang.perl.misc newsgroup.

-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Mon, 17 Aug 2009 22:26:59 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: revisiting web development in Perl...where to start?
Message-Id: <Lc1250547990159370x198af90@saturn>

In <4a84f1db$0$29034$ed362ca5@nr5-q3a.newsreader.com>,
Xho Jingleheimerschmidt <xhoster@gmail.com> mentions:
>TheGist wrote:
>> It has been a very long time since I have done
>> web programming. The last time I did this
>> was circa 2000 and at the time, like, most
>> of the world I wrote CGI pages in Perl.
>> In the years since the projects I have worked
>> on have (thankfully!) been in other directions.
>> Recently I have decided to get back into
>> some Web programming.
>> I really don't want to go down some other
>> road such as a Ruby or Java based solution.
>> Surely CGIs are
>> no longer widely used, right?
>
>I use CGI's all the time.
>
> > What is the modern
>> way to do dynamic web pages in Perl?
>
>The modern way is probably to write Perl which generates JavaScript
>which generates Flash which redirects through 18 layers of web services,
>AOP, SLAs, IoC, XML, SOBs, and web 2.0.0.0.0.0, finally producing a pale 
>blue square with a blinking orange message that says "unknown error, 
>please try again".  Modernity isn't all its cracked up to be.

That is sooooo true!

-- 
http://www.geniegate.com                    Custom web programming
Perl * Java * UNIX                        User Management Solutions


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

Date: Mon, 17 Aug 2009 22:46:41 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: revisiting web development in Perl...where to start?
Message-Id: <Lc1250548141159370x19c5e10@saturn>

In <50e78$4a84ea3e$48fb675b$15855@news.eurofeeds.com>,
TheGist <thegist@nospam.net> mentions:
>It has been a very long time since I have done
>web programming. The last time I did this
>was circa 2000 and at the time, like, most
>of the world I wrote CGI pages in Perl.
>In the years since the projects I have worked
>on have (thankfully!) been in other directions.
>Recently I have decided to get back into
>some Web programming.
>I really don't want to go down some other
>road such as a Ruby or Java based solution.
>Surely CGIs are
>no longer widely used, right? What is the modern
>way to do dynamic web pages in Perl?
>I have noticed that O'Reilly hasn't updated
>the Perl CGI book since 2000! People still use
>Perl for web programming, right?

Most people I see these days are using PHP.

That doesn't mean it's better! (I use PHP, primarily because everyone else
does.. as someone who knows their way around both, I assure you, PHP sucks)

One thing PHP does pretty good at is templating, it's a web designers
templating system, not a serious programming language.

Believe it or not, CGI is still pretty common, aside from the bloated
nature of CGI.pm, it's still a pretty good fit. There is a CGI::Lite(?)
module I used once or twice, it's good.

One thing I'm surprised no one has mentioned is FastCGI(?)

I've spoken to people who use mod_perl and they're now in the process
of moving toward "fastcgi". I like fastcgi because, with a little careful
design, you can make an application that can switch from CGI to FastCGI 
and back again. (have to use clean code for this) 

The advantage with plain CGI is, you don't consume resources for scripts
that are run maybe once a day and they're also MUCH easier to debug.

FastCGI is really good for cases that have a lot of hits, it beats the pants
off of other technologies (cough, PHP) because the process sits in memory. It's
great for loading in things like configuration data and then sharing them with
any new requests.

FastCGI is not a good fit for administrative control panels or utilities that
are seldom run.

FastCGI (indeed, any serious perl work) is generally only found with people who
know what they're doing, so if you're looking for opportunities, perl probably
isn't it. (this is very unfortunate)

You asked what people are using today, in terms of popularity, PHP wins.
(be prepared for massive irritation if you use it..)

Jamie
-- 
http://www.geniegate.com                    Custom web programming
Perl * Java * UNIX                        User Management Solutions


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

Date: 17 Aug 2009 22:09:10 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Rounding issue
Message-Id: <7eu2o6F2h71j8U1@mid.uni-berlin.de>

Marten Lehmann <lehmannmapson@cnm.de> wrote:
> Hello,

> > Marten Lehmann <lehmannmapson@cnm.de> wrote:
> >>>     ~% perl -E'say sprintf "%.40f", 0.15'
> >>>     0.1499999999999999944488848768742172978818
> >> why isn't it stored as 0.150000000000000 internally?
> >>
> >>> This is less than 0.15, so it rounds to 0.1.
> >> This is explains why 0.149 doesn't round to 0.2, but it doesn't explain 
> >> why 1.5 works different than 0.15 wuth just one floating point digit 
> >> difference.
> > 
> > Please re-read your notes from "Basics of Computer Numerics".

> although I know about the difference between an internal representation 
> and the number itself, I don't want to care about that the whole day. 

Then you better don't use floating point numbers;-)

> All I'm expecting is the programming language to remember the precision 
> I used when a value was stored. 1.5 is not an infinite value as 1/3.

And you don't have the problem with 1.5, you have it with 0.15,
which is a number that requires an infinite number of bits to
be represented exactly in binary...

It's not a question of the programming language - you will have
the same problem in all programming languages that allow you
to use floating point numbers. The first thing is that the same
problems also appears if you represent numbers in base 10 -
1/3 is the simplest example - you're used to it and thus don't
wonder what's going on. Of course, you can use Perl (or any
other language) to represent numbers in a 10 based system
(and some processors even have some kind of support for it,
see for example BCD (binary coded decimals)). But you then
have to write functions for all the arithmetic operators
printing etc. etc. and the computation speed will probably
be rather abysimal.

But the fundamental problem remains. You have an infinite
number of floating point numbers that must be represented
with a limited number of bits. Thus except for an infinitely
small fraction of them you have just approximations. And
once you have only an approximation there's no going back to
the exact number you started of with.

Asking for 0.1 + 0.05 to be output after rounding as "0.2"
when the numbers are represented in binary is exactly the
same as asking for 2.0/6.0 + 1.0/6.0 to be output as "1"
after rounding when using a base 10 representation with a
limited number of digits - it simply can't be done. That
you accept the problem when using base 10 but not when
using base 2 is just a result of being used to the limi-
tations of base 10 but less to that of base 2.

                               Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


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

Date: Tue, 18 Aug 2009 11:06:25 GMT
From: spambait@milmac.com (Doug Miller)
Subject: Re: Rounding issue
Message-Id: <h6cnl3$go7$2@news.eternal-september.org>

In article <7etmkuF2hu206U1@mid.individual.net>, Marten Lehmann <lehmannmapson@cnm.de> wrote:
>Hello,
>
>>     ~% perl -E'say sprintf "%.40f", 0.15'
>>     0.1499999999999999944488848768742172978818
>
>why isn't it stored as 0.150000000000000 internally?
>
>> This is less than 0.15, so it rounds to 0.1.
>
>This is explains why 0.149 doesn't round to 0.2, but it doesn't explain 
>why 1.5 works different than 0.15 wuth just one floating point digit 
>difference.

Of course it does. 1.5 has an exact binary representation, 0.15 does not.


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

Date: Mon, 17 Aug 2009 16:19:40 -0700
From: sln@netherlands.com
Subject: Re: Rounding issue
Message-Id: <auoj85l8m7o4q3jtmmbdranum55qtp2b0d@4ax.com>

On Mon, 17 Aug 2009 20:08:16 +0200, Marten Lehmann <lehmannmapson@cnm.de> wrote:

>Hello,
>
>I don't understand why
>
>perl -e 'print sprintf("%.0f", 1.5). "\n"'
>
>returns 2 as expected, but
>
>perl -e 'print sprintf("%.1f", 0.15). "\n"'
>
>returns 0.1, whereby I expected to get 0.2.
>
>What am I doing wrong? What do I have to do to get 0.2?
>
>Kind regards
>Marten Lehmann

As Ben said, the 1,5 is not really 1.5 in floating point terms.

However, this below gets what you want.

If your application is accounting, and your doing discreet
calculations that in PRINT you want them to add up to a correct
"visual" total, then this is what you want.

The reassignment of course is the $newval = sprintf();
You must make sure you are only dealing with fractions of cent
and that it would not be the case of it being used itteratively
in a future calculation.

At least, I wouldn't want my bank to.

-sln
=======================

use strict;
use warnings;

my $f1 = 1.5;
my $f2 = .15;

print sprintf("%.0f", $f1). "\n";
print sprintf("%.1f", $f2). "\n";
print "\n";
print sprintf("%.0f", (($f1 * 100)+5)/100 ). "\n";
print sprintf("%.1f", (($f2 * 100)+5)/100). "\n";

__END__
Output:

2
0.1

2
0.2



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

Date: Mon, 17 Aug 2009 16:31:55 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Rounding issue
Message-Id: <50qj85dtdisqnloq4jp8gp5sfeamuth2gv@4ax.com>

Marten Lehmann <lehmannmapson@cnm.de> wrote:
>> Please re-read your notes from "Basics of Computer Numerics".
>
>although I know about the difference between an internal representation 
>and the number itself, I don't want to care about that the whole day. 
>All I'm expecting is the programming language to remember the precision 
>I used when a value was stored. 1.5 is not an infinite value as 1/3.

Yes, it is when stored in binary format as virtually all computers do.
And it has nothing to do with the particular programming language but
with how your typical computer works.

Please re-read your notes from "Basics of Computer Numerics"

jue


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

Date: Mon, 17 Aug 2009 16:37:37 -0700
From: sln@netherlands.com
Subject: Re: Rounding issue
Message-Id: <77qj85t3lgaq8312k3o35c3hg461gqvj5r@4ax.com>

On Mon, 17 Aug 2009 16:19:40 -0700, sln@netherlands.com wrote:

>On Mon, 17 Aug 2009 20:08:16 +0200, Marten Lehmann <lehmannmapson@cnm.de> wrote:
>
>=======================
>
>use strict;
>use warnings;
>
>my $f1 = 1.5;
>my $f2 = .15;
>
>print sprintf("%.0f", $f1). "\n";
>print sprintf("%.1f", $f2). "\n";
>print "\n";
>print sprintf("%.0f", (($f1 * 100)+5)/100 ). "\n";
>print sprintf("%.1f", (($f2 * 100)+5)/100). "\n";
                                    ^^
I'm sorry these should be   ' + .5'

  print sprintf("%.0f", (($f1 * 100) + .5)/100 ). "\n";
  print sprintf("%.1f", (($f2 * 100) + .5)/100). "\n";

Now $f1,$f2 can be used with a common format string, like "%.1f", or "%.0f"
and be consistant.

-sln




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

Date: Mon, 17 Aug 2009 18:27:58 -0700
From: sln@netherlands.com
Subject: Re: Rounding issue
Message-Id: <ig0k851aub1j1lvr2r4tlt3o3ngdn7p4mr@4ax.com>

On Mon, 17 Aug 2009 16:37:37 -0700, sln@netherlands.com wrote:

>On Mon, 17 Aug 2009 16:19:40 -0700, sln@netherlands.com wrote:
>
>>On Mon, 17 Aug 2009 20:08:16 +0200, Marten Lehmann <lehmannmapson@cnm.de> wrote:
>>
>>=======================
>>
>>use strict;
>>use warnings;
>>
>>my $f1 = 1.5;
>>my $f2 = .15;
>>
>>print sprintf("%.0f", $f1). "\n";
>>print sprintf("%.1f", $f2). "\n";
>>print "\n";
>>print sprintf("%.0f", (($f1 * 100)+5)/100 ). "\n";
>>print sprintf("%.1f", (($f2 * 100)+5)/100). "\n";
>                                    ^^
>I'm sorry these should be   ' + .5'
>
>  print sprintf("%.0f", (($f1 * 100) + .5)/100 ). "\n";
>  print sprintf("%.1f", (($f2 * 100) + .5)/100). "\n";
>
>Now $f1,$f2 can be used with a common format string, like "%.1f", or "%.0f"
>and be consistant.
>
>-sln
>
It can be generalized.
It only works up to the width of the mantissa.
Which is what 8 digits? So don't set the width to say 40.
A width of 2 max should do fine.

-sln
===============================
use strict;
use warnings;

my $f1 = 1.5;
my $f2 = .15;

my ($n1,$n2) = (
    getFmtRound($f1,40),
    getFmtRound($f2,40)
);

print "$n1\n$n2\n\n";

print getFmtRound($f1,0),"\n";
print getFmtRound($f2,1),"\n";

sub getFmtRound
{
	my ($val,$width) = @_;
	my $fmt = "%.$width"."f";
	return sprintf $fmt,(($val * 10**($width))+.5)/(10**($width));
}
__END__

1.5000000000000000000000000000000000000000
0.1499999999999999900000000000000000000000

2
0.2



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

Date: Mon, 17 Aug 2009 18:37:29 -0700
From: sln@netherlands.com
Subject: Re: Rounding issue
Message-Id: <oa1k85t01etbd4orr40l88mgddgh6ct2pg@4ax.com>


>use strict;
>use warnings;
>
>my $f1 = 1.5;
>my $f2 = .15;
>
>my ($n1,$n2) = (
>    getFmtRound($f1,40),
>    getFmtRound($f2,40)
>);
>
>print "$n1\n$n2\n\n";
>
>print getFmtRound($f1,0),"\n";
>print getFmtRound($f2,1),"\n";
>
>sub getFmtRound
>{
>	my ($val,$width) = @_;
>	my $fmt = "%.$width"."f";
>	return sprintf $fmt,(($val * 10**($width))+.5)/(10**($width));
                                            ^^^                 ^^
	return sprintf $fmt,(($val * 10**($width+1))+.5)/(10**($width+1));

Hey sorry again, this should be $width+1. Have to affect only the last digit.
-sln



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

Date: Mon, 17 Aug 2009 15:16:56 -0700
From: Nathan Keel <nat.k@gm.ml>
Subject: Re: Social problems of Python doc [was Re: Python docs disappointing]
Message-Id: <sFkim.132666$qx1.19363@newsfe04.iad>

Jon Harrop wrote:

> Xah Lee wrote:
>> On Aug 12, 12:15 pm, Raymond Hettinger <pyt...@rcn.com> wrote:
>>> * The reason for implementing the key= parameter had nothing to do
>>> with limitations of Python's compiler.  Instead, it was inspired by
>>> the
>>> decorate-sort-undecorate pattern.
>> 
>> The decorate-sort-undecorate pattern is a compiler limitation, for
>> most of today's langs. I'm not sure, but i think some of the fancy
>> functional langs automatically detect such and optimize it away, to
>> various degrees.
> 
> You mean people use that pattern as a fast alternative in languages
> where user-defined functions are very slow, like Python and
> Mathematica?
> 


Do not give this "Xah Lee" idiot any attention. This asshole posts only
self-serving nonsense, because he thinks it makes him sound important
(when in reality, he is absolutely clueless).  This idiot always cross
posts to 5 or more different groups that have nothing to do with his
attempts to impress people (which always fail).  He's incredibly
arrogant, yet incredibly clueless.


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

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


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