[12208] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5808 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 27 21:17:22 1999

Date: Thu, 27 May 99 18:00:17 -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           Thu, 27 May 1999     Volume: 8 Number: 5808

Today's topics:
        A better way then flock? <rich_guy@hotmail.com>
        Beginner needs help <thomaslo@uiuc.edu>
    Re: check pop3 with perl? <jeff@vpservices.com>
    Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Pe <bshair@itds.com>
    Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Pe (Larry Rosler)
    Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Pe (I R A Aggie)
    Re: Help, I'll pay money for solution!!! <ppith@my-deja.com>
        online software engineering study (win prizes) <kotov@cse.ogi.edu>
        Perl addition bug(?) <APTavistock@lbl.gov>
    Re: Perl addition bug(?) <APTavistock@lbl.gov>
    Re: Perl addition bug(?) (Larry Rosler)
    Re: Perl addition bug(?) <uri@sysarch.com>
    Re: Perl and Oracle help! <raimi@cs.tu-berlin.de>
    Re: Perl, GUI and VAX VMS <sugalskd@netserve.ous.edu>
        read html source from other servers? novaya@my-deja.com
    Re: read html source from other servers? <prauz@sprynet.com>
        scalar refs and m/(pat)/ <*@qz.to>
    Re: scalar refs and m/(pat)/ <uri@sysarch.com>
    Re: scalar refs and m/(pat)/ <rra@stanford.edu>
    Re: unexponentialize field from text file (Larry Rosler)
    Re: using ~ with chdir (hymie!)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 27 May 1999 17:31:38 -0700
From: "$Richy Rich$" <rich_guy@hotmail.com>
Subject: A better way then flock?
Message-Id: <374de0b3.0@news1.starnetinc.com>


hi,

    i posted a question about the flocking technique not too long ago
and Tom Christiansen was kind enough to direct me to some info and paste
in the email reply a lot of info about how to implement flock. however,
i'm not sure if this is what i need to solve my problem. in haste i
assumed it would. here's my problem. the isp i'm on slows down to a
crawl, and I have about 40 or more users at once creating session files.
i don't think the flock command will help, as i want to increment +1 on
the session of the user and not overwrite or update the same session
file. i should have put more thought into it, sorry.

how it works, when someone enters into an active session, it creates a
session file for them, based on a session.$number. the files are limited
to how many users can access at one time, so it starts at session.1
(first user's session file is created), and ends at session.25 (if
there's a 25 user limit at the time). that's easy enough, but when this
server gets deathly slow, i notice that sometimes it will print "Bob has
entered into an active session as user #5", and directly after appended
in the log, it will say "Sarah has entered into an active session as
user #5", which shouldn't be happening. the user's session file is there
until the user times out or exits, etc. and they hadn't done either. so,
the time it takes to check if the file exists, it allows one user to
overwrite the SAME (Bob's) file, nor do i
need to WAIT for the lock to go away, but i simply need it to create
another session file incremented by 1 so Sarah enters with the session
file "session.6" for example. all the incrementing is fine and
everything works great, until the server slows down to a crawl! i'm
trying to find out it if there's a way that Perl can help me with this.
perhaps i'm wrong, but i don't think the flock command is going to help
me there. i will use it where it writes to the actual log saying who
entered where and when, but that doesn't solve my problem of two people
entering at the same time. should i just use flock on the session file
(which i will do anyway), but just have the script check again? again, i
don't want or need it to lock the file and wait for the next user to
write to it, but to increment by 1 if that file exists. would flock be
instant enough to see it's there and take away that window where it will
write for two users and see it's there to increment and add the user
into the next session number?

i'd love to get on a faster isp, but that's not going to happen right
now, and i'd love to find a way to solve this problem so it won't screw
my stuff up when my host gets too slow.

thank you so much!
rich




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

Date: Thu, 27 May 1999 19:36:27 -0500
From: ACRC <thomaslo@uiuc.edu>
Subject: Beginner needs help
Message-Id: <374DE50B.51CB@uiuc.edu>

We have some problems displaying PDF files in the secure section of our
site. Everything seems to work fine when you click on the link to a PDF
file, and Adobe Acrobat Exchange/Reader would load itself up, and after
that false hope, it would say it can't open the file. The file is OK
too.

I didn't want to put the entire script up here, so here's the section we
think is causing the problem. Any help would be appreciated. If you need
to see the entire script, please let me know. Thanks.

} elsif ($inputfile ne "" && isElementInArray($extension,
@protect_pdf_ext) && $is_group_filter_passed) {
    print "Content-type: application/pdf\n\n";
    open(PDFFILE, "<$protect_pdf_dir/$filename") ||
      &CgiDie("Could not open $protect_pdf_dir/$filename");
    while (<PDFFILE>) {
        print $_;
    }
    close (PDFFILE);


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

Date: 27 May 1999 23:34:50 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: check pop3 with perl?
Message-Id: <374DD610.8F0DB493@vpservices.com>

Jared Evans wrote:
> 
> You can check out :
> http://www.frontiernet.net/~jared/cgi-bin/popmail/
> 
> this makes use of the POP3client for perl.  Up to you to try it out- no
> information is saved (mail server, username, or the password.).

Looks cool, any chance you could post the code?

-- 
Jeff


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

Date: Thu, 27 May 1999 23:12:43 GMT
From: Bob Shair <bshair@itds.com>
Subject: Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Perl Y2K compliant?
Message-Id: <7ikjh9$f3r$1@nnrp1.deja.com>

In article <7iilcm$1dl$1@nnrp1.deja.com>,
  finsol@ts.co.nz wrote:

> Whether a method of instructing a computer can be deemed a programming
> language, scripting language, interface language, job control language
> or some other esoteric jargon you would care to name, is a grey area
> that I don't wish to debate. The fact is that CGI shares the same Y2K
> booby-trap problem as Perl. Fixing Y2K problems is more important than
> playing stupid semantics.
>

Jocelyn (dear fellow Deja-News user),

It's not clear to me what you're suggesting.

If you're trying to point out that many Perl programs will break
because real-world programmers fail to understand localtime(),
thanks.  They will.  One already has at one of my clients.
It's of value to point this out.

If you're suggesting that Perl should unilaterally change the behaviour
of localtime() to (1) break all the code which was written properly, and
(2) deviate from the behaviour used by other Unix and C programming
environments... Nah, you CAN'T be suggesting that.

localtime() is Broken-as-Designed, but it's part of the environment.

--
Bob Shair
Bob Shair Consulting
Champaign, Illinois


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 27 May 1999 16:53:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Perl Y2K compliant?
Message-Id: <MPG.11b77aca813cd52989b16@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <374dc4b4@cs.colorado.edu> on 27 May 1999 16:18:28 -0700, Tom 
Christiansen <tchrist@mox.perl.com> says...
> In comp.lang.perl.misc, ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> :I see no point in formalizing the current mish-mash.

<BIG SNIP>

> Perl is supposed to be DWIM.

The DWIMming can be, should be, and -- thanks largely to your efforts -- 
*is* documented quite thoroughly, on the whole.

Someday one might separate some of the linear prose descriptions into 
Syntax, Constraints, and Semantics, which is the level of formality of 
the C Standard language description and which is quite formal enough for 
its users.  But from what I've gleaned here about the parser, a BNF 
description of the syntax might not suffice.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 28 May 1999 00:05:03 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Perl Y2K compliant?
Message-Id: <slrn7krnjc.2uj.fl_aggie@thepentagon.com>

On Thu, 27 May 1999 23:12:43 GMT, Bob Shair <bshair@itds.com>, in
<7ikjh9$f3r$1@nnrp1.deja.com> wrote:

+ If you're suggesting that Perl should unilaterally change the behaviour
+ of localtime() to (1) break all the code which was written properly

Causing an even larger Y2K-ish problem...

James


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

Date: Thu, 27 May 1999 23:27:13 GMT
From: Howard Jow <ppith@my-deja.com>
Subject: Re: Help, I'll pay money for solution!!!
Message-Id: <7ikkcg$fqp$1@nnrp1.deja.com>

<SNIP>

> >Requirement:
> >1. I need to send it back to the address it came from (the address
which
> >came from the form) without changing the contents.
> >
> >2. I need to be able to set up a program to do this (to receive mail
and
> >send it back to the address it came from).
> >
> >Here's the catch:
> >1. I need the requirement to work ONLY during specified hours of the
day. I
> >can turn it on and off at the appropriate time.
> Does NT have something similar to the 'cron' that Unix systems have to
run
> programs at a specified time of day?  If so, it would be fairly easy
to

Ya, you can use something called WinAT.  It's a GUI interface for
scheduling tasks.  I'm sorry NT is being used as well.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 27 May 1999 17:43:08 -0700
From: Alex Kotov <kotov@cse.ogi.edu>
Subject: online software engineering study (win prizes)
Message-Id: <374DE69C.A391D7F0@cse.ogi.edu>

Dear newsgroup readers,

I would like to ask for your help.

I'm a student at the Computer Science department of the Oregon
Graduate Institute. I have been following the developments in the Open
Source community for about 4 years and I've been fascinated with the
way Open Source movement works. I've been doing research in empirical
software engineering and I was wondering if the same principle that
drives the Open Software movement can work in other areas.

The main difficulty in empirical software engineering studies is the
great variability in people's performance (sometimes as much as 25:1),
which causes a lot of "noise" in analysis. Therefore studies with 30
or 40 participants are often just not powerful enough to get credible
results.

This gave me the idea of an "Open software engineering study". Using
the same principle utilized by the Open Source software, such studies
could leverage contributions of multiple participants spread all over
the world to overcome the "noise" problem and help us better
understand the effectiveness of different software engineering methods
and techniques. All the participants would have to do is connect to a
central web server and spend a little time performing some simple
software engineering tasks online. The large number of participants
would allow us to filter out the "noise" and make a justified
conclusion about which techniques work better under which
circumstances.

This kind of study has never been attempted before and some of the
professors on my committee are not convinced that such studies would
be able to attract enough volunteers to make them worthwhile.

This is where I need your help. I have put together a survey to find
out if there are enough people in the world who would like to make a
contribution to the field by participating in an internet-based
software engineering study. If you are interested in participating (or 
even if you are not), please take 10 minutes out of your busy schedule 
to take the survey. The results of this survey should either convince
my committee that online studies might work, or convince me that I'm
wasting my time working on them.

All people who take the survey will be entered in a drawing for
prizes. 

To take the survey, point your web browsers to

http://software-engineering.cse.ogi.edu/surv/driver.cgi?R=AG

If you have any questions or comments please email me at
kotov@cse.ogi.edu or call (503)748-7385. If you know someone who might
be interested in participating, please pass this information to them!

Thank you for your time,

Alex Kotov

Pacific Software Research Center
Oregon Graduate Institute of Science and Technology


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

Date: Thu, 27 May 1999 15:41:11 -0700
From: Aaron Tavistock <APTavistock@lbl.gov>
Subject: Perl addition bug(?)
Message-Id: <374DCA07.CB19B772@lbl.gov>

Ok, I'm sure this has been gone over a half a dozen time, but I've found
a simple math bug in perl.  Simple addition does not seem to be able to
handle floating point numbers accurately.  This seems like a very basic
issue that would effect alot of processes, but it seems to exist in
perl5.004 and perl5.005.

Heres a simple script that demonstrates the problem:


#! /usr/local/bin/perl

while (1)
{
  $counter ++;
  $add += 1.1;
  $multiply = $counter * 1.1;
  $delta = $multiply - $add;
  
  print"$counter : $add : $multiply : $delta\n";
}


>From as early as the 6th iteration a delta is shown.  From about the
50th iteration the addition function shows a noticable change in its
value from the multiplication.

Now this is potentially maskable by lopping off the delta, but shouldn't
this basic math be handled by the perl interpreter?  Does anyone have
some insight into this?

Aaron Tavistock
aptavistock@lbl.gov


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

Date: Thu, 27 May 1999 16:57:55 -0700
From: Aaron Tavistock <APTavistock@lbl.gov>
Subject: Re: Perl addition bug(?)
Message-Id: <374DDC03.14FF1B03@lbl.gov>

Additional wierdness,

This is an interesting one liner.

  printf ("%.32f", 1.1);

I'm going to speculate that its the section beyond the 16th place after
the decimal thats causing this floating point problem.  Is it a fair
guess that perl uses a double long to store a float?  Is it also fair to
guess that the structure that floats are added in is larger (whereby
creating situations where the sum of the extra cruft fits back into the
double long as part of the new number)?

Also, I notice that this is more common when the number being added is
prime.

Now, I just want to point out that this is mostly academic, but it was
caused by trying to use perl to manipulate dollar amounts.  I've got
about 10000 line items that showed a total of about $1.50 loss due to
this problem.  The only solution is to simply avoid float math all
together and convert to cents (I suppose thats what real industrial
strength financial stuff does anyways).

Aaron Tavistock

Aaron Tavistock wrote:
> 
> Ok, I'm sure this has been gone over a half a dozen time, but I've found
> a simple math bug in perl.  Simple addition does not seem to be able to
> handle floating point numbers accurately.  This seems like a very basic
> issue that would effect alot of processes, but it seems to exist in
> perl5.004 and perl5.005.
> 
> Heres a simple script that demonstrates the problem:
> 
> #! /usr/local/bin/perl
> 
> while (1)
> {
>   $counter ++;
>   $add += 1.1;
>   $multiply = $counter * 1.1;
>   $delta = $multiply - $add;
> 
>   print"$counter : $add : $multiply : $delta\n";
> }
> 
> From as early as the 6th iteration a delta is shown.  From about the
> 50th iteration the addition function shows a noticable change in its
> value from the multiplication.
> 
> Now this is potentially maskable by lopping off the delta, but shouldn't
> this basic math be handled by the perl interpreter?  Does anyone have
> some insight into this?
> 
> Aaron Tavistock
> aptavistock@lbl.gov


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

Date: Thu, 27 May 1999 17:15:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl addition bug(?)
Message-Id: <MPG.11b7800048f07d37989b19@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <374DCA07.CB19B772@lbl.gov> on Thu, 27 May 1999 15:41:11 -
0700, Aaron Tavistock <APTavistock@lbl.gov> says...
> Ok, I'm sure this has been gone over a half a dozen time, but I've found
> a simple math bug in perl.  Simple addition does not seem to be able to
> handle floating point numbers accurately.

That is because the internal representation of a floating-point number 
is an approximation to its actual value.  Perl doesn't use infinite-
precision arithmetic, nor would you want it to.

Try following the values you are interested in, using "printf '%.20f'", 
and you will see clearly what is happening.  When you add repeatedly, 
roundoff errors accumulate.  When you multiply once, they don't.

Moral -- use integers as much as possible (like your counter), and 
floating-point only when necessary (as in your multiplication).

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 27 May 1999 20:30:17 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Perl addition bug(?)
Message-Id: <x73e0ikpd2.fsf@home.sysarch.com>

>>>>> "AT" == Aaron Tavistock <APTavistock@lbl.gov> writes:

  AT>   printf ("%.32f", 1.1);

  AT> I'm going to speculate that its the section beyond the 16th place
  AT> after the decimal thats causing this floating point problem.  Is
  AT> it a fair guess that perl uses a double long to store a float?  Is
  AT> it also fair to guess that the structure that floats are added in
  AT> is larger (whereby creating situations where the sum of the extra
  AT> cruft fits back into the double long as part of the new number)?

as larry said, floating point representation of decimal numbers is
always an approximation. there are many rules on how to use them
properly going back to the 50's and fortran. 

  AT> Now, I just want to point out that this is mostly academic, but it
  AT> was caused by trying to use perl to manipulate dollar amounts.
  AT> I've got about 10000 line items that showed a total of about $1.50
  AT> loss due to this problem.  The only solution is to simply avoid
  AT> float math all together and convert to cents (I suppose thats what
  AT> real industrial strength financial stuff does anyways).

i don't do financial code much in general, but when i do, i calculate in
pennies and integers. i only add the . at output time. make life very
clean and accurate. i do that in all languages. in general unless you
understad floating point math very well, don't use it for complex and
accurate calculations. and don't use it for money crunching either.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Fri, 28 May 1999 01:17:18 +0200
From: Raimi <raimi@cs.tu-berlin.de>
Subject: Re: Perl and Oracle help!
Message-Id: <Pine.SOL.3.91.990528011345.27089A-100000@cerberus.cs.tu-berlin.de>

On Thu, 27 May 1999 jknoll@my-deja.com wrote:

Hello!

> Does perl work seemlessly with Oracle databases?  Is it decently fast
> and efficient?

It works. The DBD::Oracle thing works fine.
But it is by no means fast and efficient (the Database). The overhead 
perl adds to the Database accesses is neglectable but the engine itself 
is REALLY slow. (Well, it does not get any slowser when databases grow or 
when statements get more complex...)

Don't start using Oracle below a PII 400 Mhz and 256 MB RAM.

Good Luck
 _  __
| )  |                                "What do you get if you   *    **  |
|\aimund                               multiply 6 by 9?"        * *    * |
|    |                                                          ****  *
   \_/acob                                                        *  *** O
   
             **** Remember: 21 is just half the truth ****



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

Date: 28 May 1999 00:21:40 GMT
From: Dan Sugalski <sugalskd@netserve.ous.edu>
Subject: Re: Perl, GUI and VAX VMS
Message-Id: <7iknik$524$1@news.NERO.NET>

Cameron Laird <claird@Starbase.NeoSoft.COM> wrote:
: In article <7ifk9n$2tv$1@news.NERO.NET>,
: Dan Sugalski  <sugalskd@netserve.ous.edu> wrote:
:>msutfin@my-dejanews.com wrote:
:>: Can I use PERL for GUI development from Open VMS 3GL programs? I'd like
:>: to execute PERL to display GUI's from VAX BASIC,C and send and receive
:>: data to and from the GUI forms and the 3GL programs.  Any input to this
:>: will be much helpful.
:>
:>Umm.... Those statements don't make all that much sense when taken
:>together. Are you looking to have perl on the Vax do GUI directly? If so,
:>you're sort of out of luck, as Tk doesn't (quite) work on VMS yet.
: Tk works under OpenVMS <URL:http://
: starbase.neosoft.com/~claird/comp.lang.tcl/tcl_vms.html>.
: I know of no one who has made TkPerl work under OpenVMS.

I was speaking of the Tk module, though I wasn't clear. There's a
mostly-done port of it--I think the current big problem is waiting for
events. Jesper Naur's been working on it, and there's a snapshot of what
he's been working on at
ftp://ftp.sidhe.org/VMSPerl_Community/Tk/vmstk001tar.-gz if anyone's
interested in taking a look.

					Dan


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

Date: Thu, 27 May 1999 23:22:38 GMT
From: novaya@my-deja.com
Subject: read html source from other servers?
Message-Id: <7ikk3s$fgp$1@nnrp1.deja.com>

does anyone know how to make a cgi script to read source codes of any
html pages in other servers, not my server?
it would be appreciated if anyone answers me.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 28 May 1999 00:17:16 +0000
From: Balazs Rauznitz <prauz@sprynet.com>
Subject: Re: read html source from other servers?
Message-Id: <374DE08C.A2A5180B@sprynet.com>

novaya@my-deja.com wrote:

> does anyone know how to make a cgi script to read source codes of any
> html pages in other servers, not my server?
> it would be appreciated if anyone answers me.

Using LWP::Simple class is the easiest.

B




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

Date: 28 May 1999 00:00:46 GMT
From: Eli the Bearded <*@qz.to>
Subject: scalar refs and m/(pat)/
Message-Id: <eli$9905271946@qz.little-neck.ny.us>

Is there some way to get m/(pat)/ type things to return scalar
refs instead of just read-only copies of what was matched?
This would allow things like direct manipulation of matched
blocks (eg chomp).

Elijah
------
the obvious $foo = \$1 did not do the trick


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

Date: 27 May 1999 20:25:09 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: scalar refs and m/(pat)/
Message-Id: <x77lpukplm.fsf@home.sysarch.com>

>>>>> "EtB" == Eli the Bearded <*@qz.to> writes:

  EtB> Is there some way to get m/(pat)/ type things to return scalar
  EtB> refs instead of just read-only copies of what was matched?  This
  EtB> would allow things like direct manipulation of matched blocks (eg
  EtB> chomp).

that makes little sense as $<num> variables are read only. so returning a
ref so you modify it would be wrong. IIR they are actually pseudo vars
(ala substr) which are not copies of the grabbed strings but offsets and
lengths which point into the original string.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 27 May 1999 17:35:41 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: scalar refs and m/(pat)/
Message-Id: <yl675e9gki.fsf@windlord.stanford.edu>

Uri Guttman <uri@sysarch.com> writes:
>>>>>> "EtB" == Eli the Bearded <*@qz.to> writes:

>   EtB> Is there some way to get m/(pat)/ type things to return scalar
>   EtB> refs instead of just read-only copies of what was matched?  This
>   EtB> would allow things like direct manipulation of matched blocks (eg
>   EtB> chomp).

> that makes little sense as $<num> variables are read only. so returning
> a ref so you modify it would be wrong. IIR they are actually pseudo vars
> (ala substr) which are not copies of the grabbed strings but offsets and
> lengths which point into the original string.

That's his entire point.  He wants to use that reference into the original
string to modify the original string.  I'm guessing there's no way to do
that, though.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Thu, 27 May 1999 16:35:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: unexponentialize field from text file
Message-Id: <MPG.11b7769c2514e521989b15@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7ikeqs$dha$1@mathserv.mps.ohio-state.edu> on 27 May 1999 
21:52:28 GMT, Ilya Zakharevich <ilya@math.ohio-state.edu> says...
> [A complimentary Cc of this posting was sent to Larry Rosler
> <lr@hpl.hp.com>],
> who wrote in article <MPG.11b7559c2f7c3efa989b13@nntp.hpl.hp.com>:
> > > It has nothing to do with the Perl version.  Num->str conversion is
> > > done by C RTL, so Perl will do the same C does.  AFAIK, vendors are
> > > free to use 'e'-format for values below 0.1 (I got one message to the
> > > contrary, so maybe the previous statement is not *that* correct ;-).
> > 
> > Vendors are free to do as they wish, but not if their software is touted 
> > as standards-compliant.
> > 
> > g,G ...  The style used depends on the value converted; style e (or E)
> >     will be used only if the exponent resulting from such a conversion
> >     is less than -4 or greater than or equal to the precision.  ...
> 
> Who told you that Perl uses sprintf()?  It may, and it may not:
> 
>   perl -V:d_Gconvert
>   d_Gconvert='gconvert((x),(n),(t),(b))';

As gconvert() isn't in the C Standard, it isn't standardized  :-).  Perl 
could attain that standardization by using "sprintf '%.Ng'" for suitable 
N, as documented for $OFMT ($#).

I am beginning to think that the solution of 'add 0 and let perl do the 
string-to-number-to-string conversion' isn't necessarily the best 
answer.  I've revised the code I showed before to produce a real 'E-to-
F' converter.

Some of the results aren't as happy as they might be (because of lack of 
rounding in the last bit), but most look really good.  Your taste may 
vary with this code, but your mileage won't.  All input numbers produce 
'F'-notation output, as requested.

> > I would really appreciate any help. I have a tab file with a field in
> > exponential form. I was wondering how I can convert this to a floating
> > point number in normal notation through regexp. thanks.

> > 0.20161E-01  to 0.020161
> > 0.49279E-02  to 0.004928

#!usr/local/bin/perl -w
use strict;

my $format = "%24s%23s  %20s\n";
printf $format => 'INPUT', 'N + 0', "E-to-F\n";

while (<DATA>) {
    chomp;
    my ($m, $n) = ($_, $_);
    $m =~ s{((?:\d+(?:\.\d*)?|\.\d+)[Ee][+-]?\d+)}{$1 + 0}e;
    $n =~ s{((?:\d+(?:\.\d*)?|\.\d+)[Ee][+-]?\d+)}
           {local $_ = sprintf '%.18f' => $1;
            s/(\.\d*?)0+$/$1/; s/\.$//; $_}e;
    printf $format => $_, $m, $n;
}
__END__
<data snipped -- see below>

                   INPUT                  N + 0               E-to-F

             0.20161E-01               0.020161  0.020160999999999998
             0.49279E-02              0.0049279             0.0049279
                     1e0                      1                     1
                  -.5e+1                     -5                    -5
                    1e-1                    0.1   0.10000000000000001
           1.23456789e-6        1.23456789e-006      0.00000123456789
12345678901234567890e-10       1234567890.12346    1234567890.1234567
12345678901234567890e+10  1.23456789012346e+029
                        (wrapped)       123456789012345680000000000000

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 27 May 1999 23:49:20 GMT
From: hymie@lactose.smart.net (hymie!)
Subject: Re: using ~ with chdir
Message-Id: <7iklm0$e3q$1@news.smart.net>

In our last episode, the evil Dr. Lacto had captured our hero,
  Andrew Hamilton <hamiltaj@sgi.com>, who said:
>I've tried this a couple of times, and each time it dies.
>
>I'd like to be able to do chdir("~username/path/to/dir"), but perl
>doesn't seem to like this.

~ is a shell construction.  You aren't calling a shell with chdir, so
you never get the shell to expand your ~.

>I'm not able to do something like chdir("/home/username/path/to/dir")
>because different people have their homes on different servers here.

You'll probably need to go through /etc/passwd to get a user's home
directory.  That's what ~ does.

 ..hymie!         http://www.smart.net/~hymowitz         hymie@lactose.smart.net
===============================================================================
I'm getting to the point where I don't feel the pain, and I've had enough.
I'm ready for the next time it hits me again 'cause I've gotten tough.
                                                                   --Billy Joel
===============================================================================


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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