[8244] in Perl-Users-Digest
Perl-Users Digest, Issue: 1861 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 11 17:07:22 1998
Date: Wed, 11 Feb 98 14:00:28 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 11 Feb 1998 Volume: 8 Number: 1861
Today's topics:
Re: Binary Search Trees <tchrist@mox.perl.com>
Re: Creating HTML documentation (Martin Vorlaender)
ENCTYPE="multipart/form-data" QUESTION?!? <sme@planetpod.com>
Re: ENCTYPE="multipart/form-data" QUESTION?!? (Nathan V. Patwardhan)
Error Help, Please <reisak@ciwd.com>
Re: FAQless Forays (was: Code Example Needed) <moc.care@hcajp - Reverse to get address>
Re: Finding the last line in a list? (Billy Chambless)
Re: garbage collection in perl (Andrew M. Langmead)
Help with code (dan bunner )
How Do You Write an Empty While Statement? (Kevin M Simonson)
Re: How generate counter? <tchrist@mox.perl.com>
Re: Is it possible to create a vector in a hash and tie <prsnyder@bewley.net>
Re: Is there a WILDCARD variable in PERL??? <ldanna@hotmail.com>
Re: Is there a WILDCARD variable in PERL??? (Ilya Zakharevich)
MATH <gcushing@exchange.nih.gov>
Re: MATH (Mike Stok)
Need some help ! <tapika@utu.fi>
Re: Need some help ! <moc.care@hcajp - Reverse to get address>
Negative of a minus sign is a plus? (Ronald L. Parker)
Re: Of Cards, Spindles, and Sealing wax Re: already off <totototo+newsgroups@mail.pacificcoast.net>
Re: Padding out a string (Martin Vorlaender)
PC vs PC vs PC (was: Multithreaded servers and communic <tchrist@mox.perl.com>
Re: perl -d core dump 5.004_04 <tchrist@mox.perl.com>
Re: perl -d core dump 5.004_04: qsort() (Ilya Zakharevich)
Perl Banner Rotation <jaco@mad.scientist.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Feb 1998 21:12:47 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Binary Search Trees
Message-Id: <6bt48f$mvd$2@csnews.cs.colorado.edu>
Keywords: URL correction
I wrote:
:You can find examples of this in the archive at
: http://www.perl.com/misc/CS-Talk.tar.gz
But should have said:
http://language.perl.com/misc/CS-Talk.tar.gz
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Let's say the docs present a simplified view of reality... :-)
--Larry Wall in <6940@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Wed, 11 Feb 1998 18:18:00 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Creating HTML documentation
Message-Id: <34e1dd48.524144494f47414741@radiogaga.harz.de>
Boris Boehlen (boris@i3.informatik.rwth-aachen.de) wrote:
: How can I use `pod2html' to create a HTML documentation for all
: installed Perl modules and pods?
: Or is there another tool to do this?
In the source distribution there's a script named installhtml
(which doesn't get installed by default under OS/2, BTW).
I haven't got it to work under OS/2 yet, though - it has a few
Unixisms...
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
Ceterum censeo | work: mv@pdv-systeme.de
Redmondem delendam esse. | http://www.pdv-systeme.de/users/martinv/
| home: martin@radiogaga.harz.de
------------------------------
Date: Wed, 11 Feb 1998 12:57:51 -0800
From: Stewart Eastham <sme@planetpod.com>
Subject: ENCTYPE="multipart/form-data" QUESTION?!?
Message-Id: <34E210CE.D9569B68@planetpod.com>
I working on a script that allows the user to upload files to a server
through a web browser. I have all of the PERL script up and working,
but as soon as I add the ENCTYPE="multipart/form-data" text in the
FORM tag in the HTML, I always get a "malformed header" error. My
thinking is that I need to add a line to my .htaccess file for this
directory, so that it recognizes "multipart/form-data". But I have no
idea what this tag may be.
Any help would be appreciated. Thanks a lot.
stewart eastham
sme@planetpod.com
------------------------------
Date: 11 Feb 1998 21:17:25 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: ENCTYPE="multipart/form-data" QUESTION?!?
Message-Id: <6bt4h5$h8r@fridge.shore.net>
Stewart Eastham (sme@planetpod.com) wrote:
: I working on a script that allows the user to upload files to a server
: through a web browser. I have all of the PERL script up and working,
: but as soon as I add the ENCTYPE="multipart/form-data" text in the
Are you using CGI.pm? That's all the help that I'll give you in a
Perl newsgroup.
Follow-ups set.
--
Nathan V. Patwardhan
please don't send spam to president@whitehouse.gov
------------------------------
Date: 11 Feb 1998 14:18:00 -0700
From: Reisa Kersting <reisak@ciwd.com>
Subject: Error Help, Please
Message-Id: <34E213B9.7F1D@ciwd.com>
I have a couple of scripts that I can't get to work on my nt system. I
have perl setup right because the other scripts work just fine. These
begin to work then all I get is "Document contains no data" error, do I
have the headers wrong?
perhaps the Absolute path to the output files?
Please I am ready to pull my hair out...
** please reply email, as I really need to get these up and running
today.
TIA
--
Sincerely
Reisa Kersting
Creative Images [ http://www.ciwd.com ]
ICQ 1634194
International Webmasters Association [ http://www.iwanet.org ]
A Total Solution for Quality Web Hosting and Design!
*****************************************************************
------------------------------
Date: Wed, 11 Feb 1998 15:51:19 -0600
From: "Phil Jach - Reverse to get address" <moc.care@hcajp - Reverse to get address>
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <34e21d67.0@news1.ibm.net>
After reading both of you postings, I must agree with the majority of what
you are saying. But I must make a point for those newbies out there.
I've been learning Perl for about 9 months. I think I've posted a question
here maybe 3 times tops. Those 3 times I posted, I didn't bother to read
the FAQ or check to see if someone else had already posted the question and
received an answer.
The reason I didn't, is because sometimes I have way to many things going
on. As most IT professionals know, there is always something to be learned
and never enough time to read it all.
I do read the ng's and I do post replies to some of the easy questions, I
spend a lot of time searching the Net for my own answers to my Perl
problems. That's the best way I've found to learn. Occasionally I do need
an answer and I don't have 16 hours to spend researching and testing to
discover a solution to my Perl problems.
I don't program Perl all the time, I use it as a tool. I know programming
logic, C, Perl, in an intermediate level but my primary job responsibilities
are to engineer solutions for managing hundreds of servers connected to a
WAN. So as you can see, the vast amounts of information I need to keep
abreast of can be overwhelming.
This ng is great. I hope it will always be available for everyone. Just
because people speed on the freeway doesn't mean we need to put restrictors
on everyone's cars, does it?
Tom and Steve, you are both very informative. I hope to learn a lot from
both of you.
Take care...
Steve Linberg wrote in message ...
>In article <6bshpt$26i$1@csnews.cs.colorado.edu>, tchrist@mox.perl.com
>(Tom Christiansen) wrote:
>
>> Recently, with little prior analysis beyond intuition, I tossed out
>> the flippant comment that this newsgroup would be a much more legible
>> place if we simply killfiled all postings coming from a PC (meaning Mac
>> or Windows).
>
>First off, let me just say that I would regret very much being kf'd by you
>(Tom) and the other luminaries on this group -- with whom I have enjoyed
>challenging and enlightening communication -- simply because I'm composing
>this note on my mac at work. I would love to set up a linux box here, and
>I'm working on it politically, but various Powers That Be are skeptical
>for the moment.
>
>Although I suspect many of the clueless in this ng (and elsewhere) are
>micro PC users, there are exceptions. And if you yourself happen to be
>sitting at a mac someday (you never know) and drop a pearl of wisdom into
>the group, I'd hate to miss it because I kf'd mac newsreaders!
>
>> The uncontended
>> winner for the most common sort of posting is without doubt those that
>> asked QUESTIONS ALREADY ANSWERED in the standard Perl FAQ.
>
>Yep, and this annoys everybody. I understand your aggravation as the
>author of much of it.
>
>> The next most
>> common, somewhat down the list but still getting in the way, were those
>> postings unrelated to Perl, pertaining instead strictly to matters CGI.
>
>This is even worse, and I share your opinion that the whole "CGI in 21
>days" approach is misleading and dangerous. I've been programming for
>almost 20 years, and I'm still learning about CGI. Pretty comfortable
>with the basics, but still learning cautiously.
>
>> Further investigation revealed a depressing but indisputable correlation:
>> nearly all such postings were written by someone using a PC (meaning Mac
>> or Windows) system, more often than not using a web browser with a lame,
>> patched-together USENET interface rather than a dedicated newsreader
tool.
>
>Well, this is depressing. I wish it were otherwise, but I can't say I'm
>entirely surprised.
>
>> Then there's the matter of, "I'm not a programmer, but I need to program
>> this web page". If you're not a programmer, don't try to program.
>> If you're not a surgeon, don't try to operate. In both cases, you should
>> hire someone with the professional skillset and experience necessary for
>> the job. If you won't do that, then you *are* a programmer whether for
>> income you pilot aircraft or sweep floors, and you will be held to the
>> same rigorous technical standards as any other programmer.
>
>Here's where I slow down and fret a little. Yes, I absolutely believe in
>high and formal standards, and that people need to read more first and
>resist the lazy way of tossing a FAQ into a busy newsgroup and hoping for
>someone to solve their problem for them.
>
>However, you also say:
>
>> I have two secrets for you: the first is that programming is not as hard
>> as it's made out to be -- especially with Perl on your side. The second,
>> however, is that it *is* a lot harder than it's made out to be.
>
>I absolutely agree, with both points, but especially the second.
>Programming -- especially programming *well* -- is very difficult and not
>learned quickly. People learn in different ways. I regret lacking some
>of the formal academic programming background that many people in this
>have, but I wouldn't give up for a second all those years of writing 6502
>assembly language on Apple //s. Or grappling with crufty Apple // C
>compilers that took 20 minutes to compile a 7-line program (I'm not
>exaggerating). People get their learning in different ways, and I've
>dealt with many university-trained programmers who knew their Knuth and
>could pseudocode 8 different sorting algorithms off the top of their head,
>but who were helpless when their compiler broke or the tools didn't work
>or the server went down.
>
>One of the main ways people learn is via Usenet, and we unfortunately have
>the bootstrap problem of people being informed in newsgroups -- often by
>short-tempered people, myself included, who grit their teeth at the 300th
>FAQ of the day -- that there is a FAQ to read at all. They don't know
>there is one until they come in and get flamed for not reading it.
>
>This problem is not going to go away anytime soon, I think. Perhaps the
>internet should never have been opened to commercial traffic, but there it
>is. We can't go back.
>
>Here's a half-serious question: would there be any point to any of the
>following:
>
>comp.lang.perl.newbies
>comp.lang.perl.CGI
>comp.lang.perl.advanced
>
>(that last, or something suitably scary-looking, as a place where, for
>want of a better term, a "higher-level" FAQ-free discussion of Perl issues
>could take place?)
>
>I think it is a real problem that this ng is littered with so many FAQs
>from misinformed or underinformed people. I also think that all questions
>are legitimite and deserve a forum. If there were some way to tease them
>apart, then I could Do The Right Thing by first venturing altruistically
>into comp.lang.perl.newbies, answering a few FAQs (which don't make me mad
>since I expect them there), then tune into comp.lang.perl.greybeards :)
>and catch up on my own learning.
>
>Kind regards,
>
>Steve Linberg
>NCAL Tech Monkey
>
>P.S. I learn something new every day in this group. I'm not kidding. I
>value it immensely.
>
>--
>Steve Linberg | National Center on Adult Literacy
>Systems Programmer etc. | University of Pennsylvania
>linberg@literacy.upenn.edu | http://www.literacyonline.org
------------------------------
Date: 11 Feb 1998 19:56:40 GMT
From: billy@cast.msstate.edu (Billy Chambless)
Subject: Re: Finding the last line in a list?
Message-Id: <6bsvpo$ori$1@nntp.msstate.edu>
In article <6bslcq$q0g$1@bashir.ici.net>, burt@ici.net (Burt Lewis) writes:
|> This is probably simple but I can't get it.
It's simple, but you can get it. ;)
|> I have a text file that might look something like this:
|> 1:apples:pears:peaches
|> 2:pears:peaches:pears
|> 3:peaches:apples:plums
|> I need to always be able to read the last line and grab the first field, in
|> this case the 3.
|> open(READFILE, "/files/WWW/vhtdocs/eastonmass/database2/data.txt");
ALWAYS check the return value fomr open(). It's also a good idea to put
file names in variables. THis helps you with the error message you're
going to priont when the open() fails. ;)
There are several ways to do what you want to do; just to make things
confusing, I'll show a couple here.
#!/usr/local/bin/perl -w
$file = $ARGV[0];
# really ought to check the number of arguments here...
open(READFILE, $file) || die "can't open $file : $!\n";
@list = (<READFILE>); # read the whole file into @list
close READFILE;
# Now, to get the last line from the list, we could:
# $lastline = pop(@list); # remove last element from @list
# or...
$lastline = $list[$#list]; # get last element from @list without removing
print "lastline = $lastline\n";
@fields = (split(/:/,$lastline,4)); # you already knew this. ;)
# to get the FIRST element, we could...
# $first = shift(@fields);
# or
$first = $fields[0];
print "first = $first\n";
# but that's a lot of typing.
# If we can assume that the first field is numeric, we can say:
# if ($list[$#list] =~ /\d+/) { $lastlast = $&; print "lastlast = $lastlast\n"; }
# But, I'd rather not assume that, so let's do this:
if ($list[$#list] =~ /\w+/) { $firstfield = $&; }
print "firstfield = $firstfield\n";
# So now, the program ends up being:
#!/usr/local/bin/perl -w
$file = $ARGV[0];
open(READFILE, $file) || die "can't open $file : $!\n";
@list = (<READFILE>); # you've just read the whole file into @list
close READFILE;
if ($list[$#list] =~ /\w+/) { $firstfield = $&; }
print "firstfield = $firstfield\n";
__END__
Depending on what can be in your fields, you probably will want to
modify the regexp.
--
* "And there _is_ a real world. In fact, some of you
* are in it right now." -- Gene Spafford
------------------------------
Date: Wed, 11 Feb 1998 20:50:22 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: garbage collection in perl
Message-Id: <Eo8F7z.627@world.std.com>
? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au> writes:
>In <6bp1re$7k$2@marina.cinenet.net> cberry@cinenet.net (Craig Berry) writes:
>[...]
>>Also, Perl never returns any
>>memory to the OS (it keeps it in a pool for reuse instead),
>Is this a perl thing or an OS thing?
Mostly a C library thing. On Unix, the c library functions malloc()
and free() keeps track of the amount of memory used for run time
allocations. If the programmer tries to allocate memory from malloc()
and the processes has no more available, it calls the system call
sbrk() to request more memory from the operating system. Most
implementations of free() never give back to the OS. In many cases it
can't, because it is unlikely that the freed memory is at the end.
Think of it as a multilevel parking garage with gates between
levels. If one level is full, they can open the gate to allow cars on
the new level. They can't close it though, until all the cars are out.
The function malloc() will open a new gate if all levels are full, but
most implementations of free() don't even bother checking if all the
cars are out of the next level, because malloc() will just have to
open the gates again later.
Since perl calls malloc() and free(), (or re-implements it if you say
yes to "use perl's malloc()" when building it.) it inherits this
behavior.
--
Andrew Langmead
------------------------------
Date: 11 Feb 1998 15:13:25 GMT
From: bunner@rclsgi.eng.ohio-state.edu (dan bunner )
Subject: Help with code
Message-Id: <6bsf6l$149$1@rclnews.eng.ohio-state.edu>
I am trying to write a piece of code to be used as a CGI-script.
The page is going to send the perl script alot of variables of the type
var1, var2, var3, var4, var5.
My script first parses them into an array like structure from the cgi-lib.
Using ReadParse. So my variables are all in the array $in.
I read the variables out using $in{var1}.
What I'd like to be able to do is
foreach $i (0 .. 5) {
print "<b> $in{var$i} </b>";
}
Which gives me "Invalid component in string or format"
I've tried to use eval to help out.
foreach $i (0 .. 5) {
eval (print "<b> \$in{var$i} </b>");
}
which just prints out $in{var0}, which is half correct.
and tried
foreach $i (0 .. 5) {
print "<b> eval (\$in{var$i}) </b>";
}
which prints out eval (\$in{var$i}
Any suggestions?
dan
--
****************************************************************
** Thou has not to like it -- thou hast just to do it. **
****************************************************************
------------------------------
Date: 11 Feb 1998 21:43:40 GMT
From: simonsen_nospam@skopen.dseg.ti.com (Kevin M Simonson)
Subject: How Do You Write an Empty While Statement?
Message-Id: <6bt62c$qt8@sf18.dseg.ti.com>
Keywords: empty while write
My job is to write a "perl" script for compiling a large number of
files. Those files can be divided into blocks. Two of the blocks are in-
dependent of each other; that is, nothing in the one block needs to be com-
piled before anything in the other, and vice versa. However, everything in
both blocks need to be compiled before anything in the third block can be
compiled.
I have been asked to write the script such that the jobs of compiling
files in the two different blocks get divided up between two machines, in
order to make the process go faster. It seemed like the best way to do
that would be to remote shell a job from the current job to compile one
block, use the current shell to compile the other block, and then wait in a
loop on the existence of a file the other shell created when it finished.
How would I go about doing that? I created a "perl" script for the
purpose of capturing the behavior I've seen. When I try executing it I get
the following:
h46^h/simonson/Qp} perl54 -version
This is perl, version 5.004_01
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Art
GNU General Public License, which may be found in the Per
h46^h/simonson/Qp} cat Hmm
#!/usr/local/bin/perl54 -w
while (`ls Hmm.Hmm | wc -l < 1`);
h46^h/simonson/Qp} Hmm
syntax error at Hmm line 2, near ");"
Execution of Hmm aborted due to compilation errors.
h46^h/simonson/Qp}
If you see what I'm doing wrong, feel free to mail me at
"smnsn@skopen.dseg.ti.com", or just post to this newsgroup. Thanks in ad-
vance.
---Kevin Simonson
-------------------------------------------------------------------------
Reverence To send me mail, remove "_nospam" and
the eternal. all the vowels from my login name.
------------------------------
Date: 11 Feb 1998 19:41:36 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How generate counter?
Message-Id: <6bsutg$hjt$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, chris+usenet@netmonger.net writes:
:Tom, is it possible for you to mark your useful and informative posts
:to separate them from the one-line quips? I used to read everything
:you write (I even have a perl program that e-mails posts by you,
:Randal, etc. to me), but lately I'm drowning in this sea of
:"you are satanspawn" posts.
Oh, I doubt that it can go on forever. I have to sleep sometime.
And maybe the satanspawn will read the manpages.
Maybe you could sort by size? Dunno.
Actually, one of these days we'll get a moderate group and forbid
the Known Lazy Bastards from posting there, and there we shall
find refuge from FAQs and PoBs.
:/tchrist/f:+
:75 articles selected.
Hee. :-)
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Just because you're into control doesn't mean you're in control."
--Larry Wall
------------------------------
Date: Wed, 11 Feb 1998 15:30:09 -0500
From: Philip Snyder <prsnyder@bewley.net>
To: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Is it possible to create a vector in a hash and tie it to permanent storage?
Message-Id: <34E20A51.6A4FF676@bewley.net>
I was hoping someone could help me out here. I never knew all this
documentation was there before now (never really looked actually). Anyway, I
was poking around and saw that you are supposed to be able to have html
versions out of those .pod files. So... I tried make. Anyway, it didn't
exactly like me. It says it needs ../lib/Config.pm and unfortunately I know I
don't have it there nor do I know what it needs to have in it. If someone
could point me in the right direction I would really appreciate it. Thanks!
-Philip
prsnyder@bewley.net
Tom Christiansen wrote:
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, webmaster@profind.com writes:
> :I am wondering if anyone has any experience of tying a hash, containing
> :ordinary vectors to a disk drive, and/or if this is at all possible, and
> :what the performance on something like that is.
>
> But actually meant to write:
>
> :I am wondering if anyone has any experience of tying a hash, containing
> :ordinary array references to a disk file, and/or if this is at all
> :possible, and what the performance on something like that is.
>
> The key to your quandary lies in the CPAN module, MLDBM:
>
> % cd /usr/src/perl/pod
> % grep -l MLDBM *.pod
> perldsc.pod
> perlfaq4.pod
> perltie.pod
>
> --tom
> --
> Tom Christiansen tchrist@jhereg.perl.com
>
> Sockets are the X windows of IO interfaces. --Rob Pike
------------------------------
Date: Wed, 11 Feb 1998 16:03:58 -0500
From: Larry D'Anna <ldanna@hotmail.com>
Subject: Re: Is there a WILDCARD variable in PERL???
Message-Id: <34E2123E.7B32ADDF@hotmail.com>
Bart Lateur wrote:
>
> David Cline <webmaster@pclightning.com> wrote:
>
> >I have over a hundred variables within the same CGI file called
> >$xxxxxxxx_r --- with the xxxxxxxxx being over a hundred different words,
> >but the "_r" is constent with them all. I want to add the values
> >contained within these variables together. As a DOS man, I could best
> >explain this like so:
> >
> >$sum = $*_r;
>
> Don't attempt to do something like that. You might end up
> including/changing a variable that you use for a different purpose
> altogether.
>
> Perl has a VERY NICE feature built in, that is excellent for this kind
> of stuff, and where your can only dream about in other computer
> languages. It is the hash, formerly known as associative array. It is,
> in short, an array where the indices are text.
<Sniped useful hash info>
you can use the symbol table hash %main:: instead of moving all
those variables into a hash variable. See the man pages for more info.
---------------------------------------------------
|Democracy is the worst system of government. --
|Except for all the others
| -Winston Churchill
---------------------------------------------------
Larry D'Anna "eschew obfuscation"
------------------------------
Date: 11 Feb 1998 21:36:24 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Is there a WILDCARD variable in PERL???
Message-Id: <6bt5ko$dr2$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Larry D'Anna
<ldanna@hotmail.com>],
who wrote in article <34E2123E.7B32ADDF@hotmail.com>:
> Bart Lateur wrote:
> >
> > David Cline <webmaster@pclightning.com> wrote:
> >
> > >I have over a hundred variables within the same CGI file called
> you can use the symbol table hash %main:: instead of moving all
> those variables into a hash variable. See the man pages for more info.
For a hundred variables - maybe. But one should keep in mind that
symbol table has a *huge* overhead comparing with the usual hash.
Ilya
------------------------------
Date: Wed, 11 Feb 1998 14:48:31 -0500
From: George Cushing <gcushing@exchange.nih.gov>
Subject: MATH
Message-Id: <34E2008F.D8734C37@exchange.nih.gov>
I am doing some dividing in Perl. How do I round up my results to 2
decimal digits?
I am new to Perl and will appreciate some help.
------------------------------
Date: 11 Feb 1998 20:32:47 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: MATH
Message-Id: <6bt1tf$b6@news-central.tiac.net>
In article <34E2008F.D8734C37@exchange.nih.gov>,
George Cushing <gcushing@exchange.nih.gov> wrote:
>I am doing some dividing in Perl. How do I round up my results to 2
>decimal digits?
>I am new to Perl and will appreciate some help.
There is a wealth of information provided with recent perl distributions
in the perlfaq man page,
man perlfaq
or
perldoc perfaq
should get the introductory page displayed. perlfaq4 (section 4 of the
FAQ) includes this:
Data: Numbers
Why am I getting long decimals (eg, 19.9499999999999)
instead of the numbers I should be getting (eg, 19.95)?
[useful info snipped]
To get rid of the superfluous digits, just use a format
(eg, printf("%.2f", 19.95)) to get the required precision.
This gives you two decimal places rather than 2 significant figures, and
you can use sprintf to format a value from one variable into another
rather than print it out.
Perl's printf is based onthe C library printf, the format specifiers -
introduced by a % - are described in the perlfunc manual page under
sprintf.
Please take the time to read the FAQ, if it's not in your distribution
then have a look at http://www.perl.com.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Wed, 11 Feb 1998 20:28:20 +0200
From: Tarmo Pikaro <tapika@utu.fi>
Subject: Need some help !
Message-Id: <34E1EDC4.8E17724C@utu.fi>
Ok here is my problem...
I'm writing CGI.
and I read in like this:
open (FILE,"somefile") || die "Can't Open file\n";
@XLINES=<FILE>;
close(FILE);
$SIZE=@XLINES;
for ($i=0;$i<=$SIZE;$i++) {
$recipient=$XLINES[$i];
and at this point I have string with enter at the end.
How can I convert - so there wont ne any enter ??????????
like this... $resipient2 = someactions( $resipient );
------------------------------
Date: Wed, 11 Feb 1998 15:03:43 -0600
From: "Phil Jach - Reverse to get address" <moc.care@hcajp - Reverse to get address>
Subject: Re: Need some help !
Message-Id: <34e2123b.0@news1.ibm.net>
chop(@XLINES); should work.
Tarmo Pikaro wrote in message <34E1EDC4.8E17724C@utu.fi>...
>Ok here is my problem...
>I'm writing CGI.
>and I read in like this:
>open (FILE,"somefile") || die "Can't Open file\n";
>@XLINES=<FILE>;
>close(FILE);
>$SIZE=@XLINES;
> for ($i=0;$i<=$SIZE;$i++) {
> $recipient=$XLINES[$i];
>and at this point I have string with enter at the end.
>How can I convert - so there wont ne any enter ??????????
>like this... $resipient2 = someactions( $resipient );
>
>
>
>
------------------------------
Date: Wed, 11 Feb 1998 21:28:31 GMT
From: ron@farmworks.com (Ronald L. Parker)
Subject: Negative of a minus sign is a plus?
Message-Id: <34e215f3.30173407@10.0.2.33>
There must be some sane reason why this was done, but could someone
explain what it is? This:
perl -e "$x='-1';print -$x;"
prints "+1". Meanwhile, this:
perl -e "$x='-1';print 0-$x;"
prints the more sane "1".
I understand that the "0-" signals Perl to convert $x to a numeric
representation, but why doesn't just the "-"?
More interesting ones:
perl -e "$x='-a';print -$x;" prints "+a"
perl -e "$x='a';print -$x;" prints "-a"
perl -e "$x='a-b';print -$x;" prints "-a-b" which wouldn't even be
true if this _were_ some kind of attempt at a symbolic math thingy.
perl -e "$x='-';print -$x;" prints "+"
------------------------------
Date: 11 Feb 98 11:22:18 PST
From: Rodger Whitlock <totototo+newsgroups@mail.pacificcoast.net>
Subject: Re: Of Cards, Spindles, and Sealing wax Re: already off topic on card wallopers
Message-Id: <1998Feb11.112218.9907@vmsmail.gov.bc.ca>
wdr@world.std.com wrote:
>Dan'l wrote:
>
>> And you could fold, spindle, and mutilate them as a gesture of adolescent
>> protest. (I haven't seen a spindle in a LONG time.
>
>I forget if it was a catalog or a Staples/OfficeMax, but the last
>one I saw, moderately recent (in the 1990's) had been modified for
>OSHA compliance
Here in Canada we can still get old fashioned, non-OSHA spindles at Office
Depot, in your choice of chrome, brass, or black finishes. The spikes really
aren't sharp enough to function easily, though.
----
Rodger Whitlock
------------------------------
Date: Wed, 11 Feb 1998 18:26:32 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Padding out a string
Message-Id: <34e1df48.524144494f47414741@radiogaga.harz.de>
Tan Aksoy (tan@morline.com) wrote:
: How would I pad out a string with extra characters?
: e.g. I have the number 10 but would like to represent it as a 6-digit
: number/string i.e. 000010.
sprintf '%06d', 10
See the section about sprintf() in the perlfunc POD.
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
Ceterum censeo | work: mv@pdv-systeme.de
Redmondem delendam esse. | http://www.pdv-systeme.de/users/martinv/
| home: martin@radiogaga.harz.de
------------------------------
Date: 11 Feb 1998 20:09:25 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: PC vs PC vs PC (was: Multithreaded servers and communicating object processes (proper))
Message-Id: <6bt0hl$jti$1@csnews.cs.colorado.edu>
Keywords: PC threads grammar sarcasm
I wrote:
:This is a fully multithreaded application, by which there are many threads
:of control -- separate PCs -- all running within the same program.
:Those who disparage fork can go read my posting of last week entitled
:"Fork is cheap and powerful". And furthermore, I challenge these people
:to rewrite this server for Soloris/Linux/POSIX threads or in particular,
:how you would do so under Windows. Go ahead. Make my day. Show me.
The PC people have told me that I'm not using the PC word in a PC way.
Fine. Here's the customary definitions of that multply overloaded word
as used by me and programmers of my acquaintance.
PC: "politically correct"; either a mostly harmless but occasionally
obfuscatory circumlocution used to avoid needless insult and emotional
injury, or else an ominous appelation from the Right used to fascistly
censor all signs of sensitivity to the human condition that might
otherwise emanate from the Center or Left.
PC: "program counter"; one of the machine's fundamental registers,
whose value indicates the current machine-level instruction
being executed. A program that forks several times has several
PCs operating on the same code. Largely synonymous with "thread
of control". Cf "SP".
PC: "personal computer"; a generic term meaning anyone's own computer.
This has nothing to do with its hardware or software, but rather
only its ownership and habitual use status. Many of us have
Sparcs as our PCs.
PC: "pessimally configured": like the previous definition but now having a
much more watered-down meaning, thanks to the Monoposoft Hegemony.
This popular but embarrassingly primitive single-user machine is
bereft of a technically respectable operating system or sane hardware,
typically cursed with a Macintosh or Windows program-loader saddled
with a GUI of dubious caliber. Upgrading your Apple PC or Intel PC
to Unix, Plan9, VMS, or Rhapsody automatically converts the erstwhile
PC into a power-user's superstation, at least in popular parlance.
Usually when I say "PC", I mean definition number two, and only rarely
number three.
I do not use definition four because I refuse to further the Evil Empire's
goal to equate all personal computer equipment used by an individual to
a specific and entirely mediocre platform that they ruthlessly control.
As for the first, I'm not big on political correctness, one way or the
other, but I fear seeing the term used to silence anyone.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Q. Why is this so clumsy?
A. The trick is to use Perl's strengths rather than its weaknesses.
--Larry Wall in <8225@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: 11 Feb 1998 20:12:01 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl -d core dump 5.004_04
Message-Id: <6bt0mh$jti$2@csnews.cs.colorado.edu>
Keywords: bug sort
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Steven Smith <steves@wco.com> writes:
:My problem was that I had a <= > b, not $a <=> $b. But should this
:generate a core file?
Certainly not. I suggest you send it in. Well, once you make
sure it's not the coredump warned about in perlfunc regarding
inconsistent sort comparison routine results.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Why do trans-atlantic transfers take so long?"
"Electrons don't swim very fast." -john@minster.york.ac.uk and whh@PacBell.COM
------------------------------
Date: 11 Feb 1998 20:31:09 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: perl -d core dump 5.004_04: qsort()
Message-Id: <6bt1qd$4i3$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Steven Smith
<steves@wco.com>],
who wrote in article <34E1FCDA.2AE6@wco.com>:
> Steven Smith wrote:
> > #!/usr/local/bin/perl
> > @files = sort { a <=> b } @files;
> My problem was that I had a <= > b, not $a <=> $b. But should this
> generate a core file?
Yes. Returning a constant -1 from sort subroutine will lead to core
dump with *many* implementations of qsort().
Newer Perls have their own robust-and-quick qsort(), thus should not
exhibit this behaviour.
Hope this helps,
Ilya
------------------------------
Date: Wed, 11 Feb 1998 23:32:54 +0200
From: "Jaco Greeff" <jaco@mad.scientist.com>
Subject: Perl Banner Rotation
Message-Id: <6bt5ud$3p4$1@news01.iafrica.com>
Hi,
I was wondering is there is any really good banner rotation software
(similar to the kind LinkExchange uses) available for a small price (free is
always better :). This software needs to be in perl because I want to
integrate parts of my existing code into the codebase. Any ideas?
Thanks in advance,
Jaco Greeff
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 1861
**************************************