[13270] in Perl-Users-Digest
Perl-Users Digest, Issue: 680 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 30 14:17:29 1999
Date: Mon, 30 Aug 1999 11:10:18 -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 Mon, 30 Aug 1999 Volume: 9 Number: 680
Today's topics:
ROUNDING NUMBERS -- HELP ME <sharif@monisys.ca>
Re: ROUNDING NUMBERS -- HELP ME <sariq@texas.net>
Re: ROUNDING NUMBERS -- HELP ME <jbc@shell2.la.best.com>
Re: SHTML and PERL <delete.the.nospam.kayec@gov.ns.ca>
Re: STDIN, Arrays and Win32 <lit280@us.ibm.com>
Subst text in file with variable contents bigtrain23@my-deja.com
Subst text in file with variable contents bigtrain23@my-deja.com
sybase, perl and bcp (ErwanPia)
tmpdir module 1.0 <sanface@sanface.com>
Want to use PERL to run script on another server. <Mark.Conlin@bridge.bellsouth.com>
Win32::ODBC <vinh.bui@medstat.com>
write to a file in a loop <lakmal@ml.com>
writing to a file within a loop <lakmal@ml.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 30 Aug 1999 12:00:53 -0400
From: "Sharif Aly" <sharif@monisys.ca>
Subject: ROUNDING NUMBERS -- HELP ME
Message-Id: <7qe9vg$j34$1@nntp1.uunet.ca>
How do I round numbers?? I need to round integers off to 2 decimal places.
Please help me it's important!
Sharif Aly
sharif@monisys.ca
------------------------------
Date: Mon, 30 Aug 1999 11:21:48 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: ROUNDING NUMBERS -- HELP ME
Message-Id: <37CAAF9C.972915F3@texas.net>
Sharif Aly wrote:
>
> I need to round integers off to 2 decimal places.
Must be 'The New Math'.
- Tom
------------------------------
Date: 30 Aug 1999 17:39:36 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: ROUNDING NUMBERS -- HELP ME
Message-Id: <37cac1d8$0$207@nntp1.ba.best.com>
Sharif Aly <sharif@monisys.ca> wrote:
> How do I round numbers?? I need to round integers off to 2 decimal places.
> Please help me it's important!
This immediately begs the question, important for whom? You probably
mean it's important for you. To the extent your message could be
interpreted as implying it's important for the other people
participating in this group, though, it's probably going to annoy some
people. You'll doubtless be hearing from some of those folks, if you
haven't already.
To the extent your problem really justifies the sense of urgency your
message displays, you would be better off consulting the Perl
documentation, which is included with every distribution of Perl. You
would be virtually certain to find an answer to a common question
like this much more quickly that way than by posting to Usenet.
For example, if I were in your position, and didn't know how to round
off a number, I could try using the perldoc program that is installed
along with all recent versions of Perl, and which, as of the latest
Perl version, includes a -q command line switch to search for keywords
in the headers of the Perl FAQ documents:
[jbc@buffy jbc]$ perldoc -q round
=head1 Found in /usr/lib/perl5/5.00503/pod/perlfaq4.pod
=head2 Does Perl have a round() function? What about ceil() and
floor()? Trig functions?
Remember that int() merely truncates toward 0. For rounding to a
certain number of digits, sprintf() or printf() is usually the easiest
route.
printf("%.3f", 3.1415926535); # prints 3.142
[rest of the interesting output snipped]
And there you go: The answer is to use printf (or sprintf). The given
answer rounds to three places to the right of the decimal point, rather
than two, so you should probably resist the urge to guess as to how
that %.3f thing should be modified to make it round to two places
(though your guess would probably be correct, in this case) and instead
consult the documentation for the printf function. Again using perldoc,
this time with the -f switch (which treats its argument as the name of
a function to look up in the perlfunc man page):
jbc@buffy jbc]$ perldoc -f printf
=item printf FILEHANDLE FORMAT, LIST
=item printf FORMAT, LIST
Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that
C<$\> (the output record separator) is not appended. The first
argument of the list will be interpreted as the C<printf()> format. If
C<use locale> is in effect, the character used for the decimal point in
formatted real numbers is affected by the LC_NUMERIC locale. See
L<perllocale>.
Don't fall into the trap of using a C<printf()> when a simple
C<print()> would do. The C<print()> is more efficient and less
error prone.
[output ends]
Hmmm. Not much use in and of itself, though it does contain a
hopeful-sounding reference to sprintf. Returning to perldoc -f:
[jbc@buffy jbc]$ perldoc -f sprintf
=item sprintf FORMAT, LIST
[snip]
Perl's C<sprintf()> permits the following universally-known
conversions:
[snip]
%f a floating-point number, in fixed decimal notation
[snip]
Perl permits the following universally-known flags between the C<%>
and the conversion letter:
[snip]
.number "precision": digits after decimal point for
floating-point, max length for string, minimum length
for integer
And there you have it: You should change the 3 in %.3f to a 2, so you
would get something like:
$pi = 3.14159265
printf "%.2f", $pi;
which would print '3.14'.
More about printf and sprintf was recently discussed in this group in a
thread titled "Will you help me solve this", which you should check
out, probably, if you're still looking for more information. You get
points in the Subject-line department for making your subject more
specific to your actual question, though you lose points with those who
care about such things by virtue of the ALL CAPS subject line (which
many interpret as shouting). And both you and that other author lose
points for the 'help me' part, which some people around here (not me,
but some others who are very good sources of information, normally) use
as the basis of automatic filtering programs that prevent them from
ever seeing messages that have that in the subject header. They
consider it a sign of a person who is greedily expecting others to do
their work for them, rather than being willing to make a good-faith
effort on their own before coming to this group for help.
Personally, I think most of the people who get flamed (or ignored) for
this particular transgression actually *have* made a good faith effort
beforehand. It's just that their good-faith efforts are a lot less
effective than most experts would expect, given the wide gulf in
expertise between those experts and the person asking for help.
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: Mon, 30 Aug 1999 16:45:35 GMT
From: "kayec" <delete.the.nospam.kayec@gov.ns.ca>
Subject: Re: SHTML and PERL
Message-Id: <Pyyy3.61$O15.2013@sapphire.mtt.net>
Abigail wrote in message ...
You read the documentation of your server, which will probably tell
you that it is a silly idea. But whatever your servers documentation
says, that has nothing to do with Perl. (It's Perl, not PERL).
========
So no one uses server side includes with pErL ?
{} I think i could write a page and than redirect the user to it, but if you
{} get a lot of hits the page may get overwritten before the user gets
there?
Then make sure you don't get a lot of hits!
========
What's the fun in that? Perhaps i could just do a mailto: link and manually
key in any new bulletin entries.
: (
DOH !
------------------------------
Date: Mon, 30 Aug 1999 12:37:42 -0400
From: "Philip M. Cohen" <lit280@us.ibm.com>
Subject: Re: STDIN, Arrays and Win32
Message-Id: <37CAB355.24042673@us.ibm.com>
elephant wrote:
> C:\>copy con x.pl
> #!perl -w
> use strict;
>
> my @a = <STDIN>;
>
> print ":: $_" for @a;
> __END__
> ^Z
> 1 file(s) copied.
>
> C:\>perl x.pl
> abc
> def
> ghi
> ^Z
> :: abc
> :: def
> :: ghi
>
> C:\>
When I try this, the control-Z works as stated for creation of x.pl (have
to press
Enter afterward), but when I run x.pl, control-Z immediately terminates
input (no
Enter needed, or even possible). And the output is different. The first
time:
C:\>perl x.pl
abc
def
ghi
:: abc
:: def
:: ghi
C:\>
And thereafter, the first output line after control-Z disappears:
C:\>perl x.pl
abc
def
ghi
:: def
:: ghi
C:\>
This happens regardless of what I print as the first line after control-Z.
Every once in a while :: abc (or whatever) will reappear and then go away
again, but ^Z never shows up.
This happens on both my home and work Win95 systems, using ActiveState's
build 519 of Perl 5.005_03.
PMC
------------------------------
Date: Mon, 30 Aug 1999 16:56:38 GMT
From: bigtrain23@my-deja.com
Subject: Subst text in file with variable contents
Message-Id: <7qed3u$vdd$1@nnrp1.deja.com>
all,
i'm trying to open a file for writing (file
contains info i want to keep), search for the
string 'defaultgateway=' (no quotes) and subtitute
a variable's value for whatever comes after the
equal sign. how do i do this?
thanks,
bigtrain
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 30 Aug 1999 16:56:39 GMT
From: bigtrain23@my-deja.com
Subject: Subst text in file with variable contents
Message-Id: <7qed40$vdf$1@nnrp1.deja.com>
all,
i'm trying to open a file for writing (file
contains info i want to keep), search for the
string 'defaultgateway=' (no quotes) and subtitute
a variable's value for whatever comes after the
equal sign. how do i do this?
thanks,
eric
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 30 Aug 1999 14:51:27 GMT
From: erwanpia@aol.com (ErwanPia)
Subject: sybase, perl and bcp
Message-Id: <19990830105127.04621.00002574@ng-cg1.aol.com>
Hi,
would anyone have an example of how to use the Sybperl Bcp functions to do a
bcp out from a table to a file ? So far I have found and example of how to do a
BCP in ...
Thanks,
Erwan Pianezza,
Dublin.
------------------------------
Date: 30 Aug 1999 17:51:00 GMT
From: SANFACE Software <sanface@sanface.com>
Subject: tmpdir module 1.0
Message-Id: <7qega4$iqs$1@play.inetarena.com>
Every PERL tool use temporary files.
If you want your code can be simply portable on different OS, you need
to select the correct tempory directory (the other solution is to use
./ directory).
The purpose of this module is to automathize the configuration of the
temporary directory in every OS supported by PERL.
We need your help.
We ask you to send us the correct tempory directory for every OS
supported by PERL and to suggest us good modifies
<sanface@sanface.com>).
At the moment this is the list of OS supported:
Windows 32 bit ('95, '98, NT) c:/temp/ (or c:/windows/temp/)
AIX Solaris IRIX Linux /tmp/
Mac /desktop folder/temp/
OpenVMS /sys\$scratch/ (or SYS\$SCRATCH)
If the module can't recognize your OS the temporary directory is set to
./
Use testtmpdir.pl to test the module on your OS and testOS.pl to know
the value of $^O PERL variable on your OS.
Copyright 1999, SANFACE Software
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Availability
The latest version of this library is likely to be available from:
http://www.sanface.com
and at every CPAN mirror (
http://www.perl.com/CPAN/authors/id/S/SA/SANFACE/ )
--
SANFACE Software
http://www.sanface.com
mailto:sanface@sanface.com
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 30 Aug 1999 12:48:05 -0400
From: Mark Conlin <Mark.Conlin@bridge.bellsouth.com>
Subject: Want to use PERL to run script on another server.
Message-Id: <37CAB5C5.EDDC11DE@bridge.bellsouth.com>
I would like to use PERL to run another PERL script on a different
server.
Is there a way to access the script as if I had hit it with a web
browser, from
inside a different script on a different server ?
thanks
------------------------------
Date: Mon, 30 Aug 1999 14:12:19 GMT
From: Vinh T. Bui <vinh.bui@medstat.com>
Subject: Win32::ODBC
Message-Id: <7qe3fp$nkc$1@nnrp1.deja.com>
I have the following script, but the results shows nothing. Can
someone tell me what I am doing wrong?
use Win32::ODBC;
$db = new Win32::ODBC("DSN=***; UID=***; PWD=***");
$db->Sql("SELECT * FROM ***");
@FieldNames = $db->FieldNames();
$x = 0;
for ($x=0; $x<50; $x++) {
print "$x $FieldNames[$x]<BR>"; }
while($db->FetchRow()){
$Data = $db->DataHash();
print "$Data<BR>"; }
$db->Close();
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 30 Aug 1999 12:44:10 -0400
From: Lakmal Jinadasa <lakmal@ml.com>
Subject: write to a file in a loop
Message-Id: <37CAB4DA.54B2DE23@ml.com>
Hi,
I have the following problem.
I open a file within a foreach loop
then try to write some data to the file.
everything goes fine except the data is not in the file.
Part of the program is as follows
foreach $key1(@list1)
foreach $key2 (@list2) {
open DAT ">File_Name";
@arr = output_of _a function;
print DAT @arr;
}
close (DAT);
}
Seperate file is created for each key1.key2
The files are there with 0 byte length.
Can anybody Help Me
Thanks
-Lakmal
------------------------------
Date: Mon, 30 Aug 1999 12:47:29 -0400
From: Lakmal Jinadasa <lakmal@ml.com>
Subject: writing to a file within a loop
Message-Id: <37CAB5A1.38DCD6B0@ml.com>
Hi,
I have the following problem.
I open a file within a foreach loop
then try to write some data to the file.
everything goes fine except the data is not in the file.
Part of the program is as follows
foreach $key1(@list1)
foreach $key2 (@list2) {
open DAT ">File_Name";
@arr = output_of _a function;
print DAT @arr;
close (DAT);
}
}
Seperate file is created for each key1.key2
The files are there with 0 byte length.
Can anybody Help Me
Thanks
-Lakmal
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
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 V9 Issue 680
*************************************