[13262] in Perl-Users-Digest
Perl-Users Digest, Issue: 672 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 29 07:07:17 1999
Date: Sun, 29 Aug 1999 04:05:08 -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 Sun, 29 Aug 1999 Volume: 9 Number: 672
Today's topics:
*HTTP_REFERER IN STUPID NETSCAPE!!??!?!?!?!? <admin@cyberthrill.com>
*HTTP_REFERER IN STUPID NETSCAPE!!??!?!?!?!? <admin@cyberthrill.com>
[Perl] How to find the Perl FAQ <rootbeer&pfaq*finding*@redcat.com>
Re: email address verification <rra@stanford.edu>
Re: Encryption <jmyers@nefarious.the-sanitarium.com>
Re: help on debug: Odd number of elements in hash list (Larry Rosler)
Re: help on debug: Odd number of elements in hash list <tungyat@yahoo.com>
Re: help on debug: Odd number of elements in hash list (Abigail)
Help with /etc/passwd (how can I switch users in perl) <phillip@mymailbag.com>
Re: Larry's and Guido's REAL sigs <wyzelli@yahoo.com>
mail client having problems with script generated mail sandals@my-deja.com
Re: Pattern Matching (Bart Lateur)
Re: Perl Y2K Bugs on the Internet <firstsql@ix.netcom.com>
Re: Perl Y2K Bugs on the Internet <firstsql@ix.netcom.com>
regex bug: (?:\d{3})+ loses count (Bart Lateur)
run perl by browser <andriani@singnet.com.sg>
Re: run perl by browser (elephant)
Re: unicode and perl (Abigail)
Re: Will you help me solve this <jbc@shell2.la.best.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 29 Aug 1999 17:17:21 +1000
From: *briguy* <admin@cyberthrill.com>
Subject: *HTTP_REFERER IN STUPID NETSCAPE!!??!?!?!?!?
Message-Id: <37C8DE81.ACFBD4AB@cyberthrill.com>
helllllpppppp.
when i load a .pl file from a html file on the server with netscape, the
http_referer environment variable is always returned as empty, however
when i load the perl script again from the html file using explorer the
HTTP_REFERER evnvoronment variable is always eturned with a value...
whats the deal with nentscape... i jsut need to make sure people aren't
runnign my scripts with a link from a domain other then mine, thankx.
please let me know, im really in need of an answer.
thankx again.
*HTTP_REFERER IN STUPID NETSCAPE!!??!?!?!?!?
------------------------------
Date: Sun, 29 Aug 1999 17:40:06 +1000
From: *briguy* <admin@cyberthrill.com>
Subject: *HTTP_REFERER IN STUPID NETSCAPE!!??!?!?!?!?
Message-Id: <37C8E3D6.692C49BF@cyberthrill.com>
helllllpppppp.
when i load a .pl file from a html file on the server with netscape, the
http_referer environment variable is always returned as empty, however
when i load the perl script again from the html file using explorer the
HTTP_REFERER evnvoronment variable is always eturned with a value...
whats the deal with nentscape... i jsut need to make sure people aren't
runnign my scripts with a link from a domain other then mine, thankx.
please let me know, im really in need of an answer.
thankx again.
*HTTP_REFERER IN STUPID NETSCAPE!!??!?!?!?!?
------------------------------
Date: Sun, 29 Aug 1999 10:24:01 GMT
From: Tom Phoenix <rootbeer&pfaq*finding*@redcat.com>
Subject: [Perl] How to find the Perl FAQ
Message-Id: <pfaqmessage935922241.8026@news.teleport.com>
Archive-name: perl-faq/finding-perl-faq
Posting-Frequency: weekly
Last-modified: 18 Aug 1999
[ That "Last-modified:" date above refers to this document, not to the
Perl FAQ itself! The last major update of the Perl FAQ was in Summer of
1998; of course, ongoing updates are made as needed. ]
For most people, this URL should be all you need in order to find Perl's
Frequently Asked Questions (and answers).
http://www.cpan.org/doc/FAQs/
Please look over (but never overlook!) the FAQ and related docs before
posting anything to the comp.lang.perl.* family of newsgroups.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Beginning with Perl version 5.004, the Perl distribution itself includes
the Perl FAQ. If everything is pro-Perl-y installed on your system, the
FAQ will be stored alongside the rest of Perl's documentation, and one
of these commands (or your local equivalents) should let you read the FAQ.
perldoc perlfaq
man perlfaq
If a recent version of Perl is not properly installed on your system,
you should ask your system administrator or local expert to help. If you
find that a recent Perl distribution is lacking the FAQ or other important
documentation, be sure to complain to that distribution's author.
If you have a web connection, the first and foremost source for all things
Perl, including the FAQ, is the Comprehensive Perl Archive Network (CPAN).
CPAN also includes the Perl source code, pre-compiled binaries for many
platforms, and a large collection of freely usable modules, among its
560_986_526 bytes (give or take a little) of super-cool (give or take
a little) Perl resources.
http://www.cpan.org/
http://www.perl.com/CPAN/
http://www.cpan.org/doc/FAQs/FAQ/html/
http://www.perl.com/CPAN/doc/FAQs/FAQ/html/
You may wish or need to access CPAN via anonymous FTP. (Within CPAN,
you will find the FAQ in the /doc/FAQs/FAQ directory. If none of these
selected FTP sites is especially good for you, a full list of CPAN sites
is in the SITES file within CPAN.)
California ftp://ftp.cdrom.com/pub/perl/CPAN/
Texas ftp://ftp.metronet.com/pub/perl/
South Africa ftp://ftp.is.co.za/programming/perl/CPAN/
Japan ftp://ftp.dti.ad.jp/pub/lang/CPAN/
Australia ftp://cpan.topend.com.au/pub/CPAN/
Netherlands ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
Switzerland ftp://sunsite.cnlab-switch.ch/mirror/CPAN/
Chile ftp://ftp.ing.puc.cl/pub/unix/perl/CPAN/
If you have no connection to the Internet at all (so sad!) you may wish
to purchase one of the commercial Perl distributions on CD-Rom or other
media. Your local bookstore should be able to help you to find one.
Another possibility is to use one of the FTP-via-email services; for
more information on doing that, send mail to <mail-server@rtfm.mit.edu>
(not to me!) with these lines in the body of the message, flush left:
setdir usenet-by-group/news.announce.newusers
send Anonymous_FTP:_Frequently_Asked_Questions_(FAQ)_List
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Comments and suggestions on the contents of this document
are always welcome. Please send them to the author at
<pfaq&finding*comments*@redcat.com>. Of course, comments on
the docs and FAQs mentioned here should go to their respective
maintainers.
Have fun with Perl!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 28 Aug 1999 23:05:15 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: email address verification
Message-Id: <ylu2pj15r8.fsf@windlord.stanford.edu>
Jon Hollcraft <webmaster@mendonet.com> writes:
> Man, now THAT is really hitting below the belt! I post a little chunk
> of code to help a fellow neophyte, and you gotta bust my chops.
It's just a long-standing discussion here. :)
> How about this then if($in{'address'}!~ /@/){&bademail}
Oh, I don't know, I can send mail to stanford.edu!rra and it works fine...
Not really RFC 822 compliant, though, I suppose.
--
#!/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: Sun, 29 Aug 1999 00:55:12 -0500
From: "J. A. Myers" <jmyers@nefarious.the-sanitarium.com>
Subject: Re: Encryption
Message-Id: <37C8CB40.43E246E2@nefarious.the-sanitarium.com>
You will find the answer to most module questions at www.cpan.org .
You will find a PGP module there.
------------------------------
Date: Sat, 28 Aug 1999 23:06:56 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: help on debug: Odd number of elements in hash list at ././rt.pl line 56, <STDIN> chunk 1
Message-Id: <MPG.12326dd6db27131989ecb@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <Bt3y3.1216$p11.55835@news1.rdc2.on.home.com> on Sun, 29 Aug
1999 05:23:45 GMT, Winter <tungyat@yahoo.com> says...
> Anyone know what is the meaning of "Odd number of elements in hash list at
> ././rt.pl line 56, <STDIN> chunk 1"?
All Perl error messages are explained in perldiag.
> Any help is appreipate, I would prefer reply via email at tungyat@yahoo.com
No address munge, no problem.
> Thanks in advanced.
You're welcome.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 29 Aug 1999 06:41:30 GMT
From: "Winter" <tungyat@yahoo.com>
Subject: Re: help on debug: Odd number of elements in hash list at ././rt.pl line 56, <STDIN> chunk 1
Message-Id: <uC4y3.1226$p11.56399@news1.rdc2.on.home.com>
Yeah I think I understand %hash, if not very well..
I just doing normal stuff.. here is part of my code:
$sth = $dbh->query($qu);
die "SQL Error: $Mysql::db_errstr" if (! defined $sth);
for(;;) {
my %fh2;
last if ! ( %fh2 = $sth->FetchHash() );
... ...
}
I was trying to fetch row from the query result.... my sample query suppose
to return three row. but the error (Odd number blah blah...) occurs at the
second iteration...
Anyhelp?
Joe Kline <jkline@one.net> wrote in message
news:37C8C7BD.B2F72D05@one.net...
>
>
> Winter wrote:
> >
> > Hi all,
> >
> > Anyone know what is the meaning of "Odd number of elements in hash list
at
> > ././rt.pl line 56, <STDIN> chunk 1"?
> >
>
> Consulting the ever bountiful 'perldoc perldiag' we find:
>
> "...You specified an odd number of elements to initialize a hash,
> which is odd, because hashes come in key/value pairs."
>
> Maybe you need to also look at 'perldoc perldata' to achieve a better
> understanding of Perl's wonderful data structures.
>
> joe
>
>
> -----------== Posted via Newsfeeds.Com, Uncensored Usenet News
==----------
> http://www.newsfeeds.com The Largest Usenet Servers in the World!
> ------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers
==-----
------------------------------
Date: 29 Aug 1999 03:52:33 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: help on debug: Odd number of elements in hash list at ././rt.pl line 56, <STDIN> chunk 1
Message-Id: <slrn7shtbu.23d.abigail@alexandra.delanet.com>
Winter (tungyat@yahoo.com) wrote on MMCLXXXIX September MCMXCIII in
<URL:news:Bt3y3.1216$p11.55835@news1.rdc2.on.home.com>:
~~
~~ Anyone know what is the meaning of "Odd number of elements in hash list at
~~ ././rt.pl line 56, <STDIN> chunk 1"?
Did you check "man perldiag"?
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sun, 29 Aug 1999 00:44:51 -0700
From: "Phillip Casalegno" <phillip@mymailbag.com>
Subject: Help with /etc/passwd (how can I switch users in perl)
Message-Id: <7qapeg$mdk$2@nntp9.atl.mindspring.net>
Hello,
I am trying to write a CGI script to take web input and modify the
/etc/passwd. I know it is a security problem, but I am trying to do it
anyway.
Does anyone know of a good way to do this. My way involves the exec
function and the adduser command. To do this I need to be root. Does anyone
know of a way to switch the user while in a perl script?
Thanks,
Phil Casalegno
phillip@mymailbag.com
------------------------------
Date: Sun, 29 Aug 1999 16:55:20 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Larry's and Guido's REAL sigs
Message-Id: <Tf5y3.5$P%4.3645@vic.nntp.telstra.net>
Larry Rosler <lr@hpl.hp.com> wrote in message
news:MPG.1232675d6e885633989ec9@nntp.hpl.hp.com...
> In article <7q9v2u$1jk$1@nnrp1.deja.com> on Sun, 29 Aug 1999 00:32:30
> GMT, aaron_watters@my-deja.com <aaron_watters@my-deja.com> says...
> ...
> > http://www.chordate.com/sigs.GIF
> >
> > enjoy! -- Aaron Watters
>
> Can't. No such page. Even with lower-case .gif. Try again?
>
Works for me...
Wyzelli
------------------------------
Date: Sun, 29 Aug 1999 07:14:21 GMT
From: sandals@my-deja.com
Subject: mail client having problems with script generated mail
Message-Id: <7qamk9$g8a$1@nnrp1.deja.com>
I have a CGI script that sends mail. HOwever when I try to get the mail
it sents for some reason outlook express can't download the mail. I get
a message indicating that my POP3 server is not responding. However if
if go to my Windows NT based mail server, and manually delete the one
email, outlook express is then able to download the rest of my mail.
Another stange thing is that if I send the mail to a Unix hosted mail
server, I can download the mail. All ideas are welcomed.
The code that seems to be casing the problem is:
sub sendmail {
# error codes below for those who bother to check result codes <gr>
# 1 success
# -1 $smtphost unknown
# -2 socket() failed
# -3 connect() failed
# -4 service not available
# -5 unspecified communication error
# -6 local user $to unknown on host $smtp
# -7 transmission of message failed
# -8 argument $to empty
#
# Sample call:
#
# &sendmail($from, $reply, $to, $smtp, $subject, $message );
#
# Note that there are several commands for cleaning up possible bad
inputs - if you
# are hard coding things from a library file, so of those are
unnecesssary
#
my ($fromaddr, $replyaddr, $to, $smtp, $subject, $message) = @_;
$to =~ s/[ \t]+/, /g; # pack spaces and add comma
$fromaddr =~ s/.*<([^\s]*?)>/$1/; # get from email address
$replyaddr =~ s/.*<([^\s]*?)>/$1/; # get reply email address
$replyaddr =~ s/^([^\s]+).*/$1/; # use first address
$message =~ s/^\./\.\./gm; # handle . as first character
$message =~ s/\r\n/\n/g; # handle line ending
$message =~ s/\n/\r\n/g;
$smtp =~ s/^\s+//g; # remove spaces around $smtp
$smtp =~ s/\s+$//g;
if (!$to)
{
return(-8);
}
if ($SMTP_SERVER ne "")
{
my($proto) = (getprotobyname('tcp'))[2];
my($port) = (getservbyname('smtp', 'tcp'))[2];
my($smtpaddr) = ($smtp =~
/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
? pack('C4',$1,$2,$3,$4)
: (gethostbyname($smtp))[4];
if (!defined($smtpaddr))
{
return(-1);
}
if (!socket(MAIL, AF_INET, SOCK_STREAM, $proto))
{
return(-2);
}
if (!connect(MAIL, pack('Sna4x8', AF_INET, $port, $smtpaddr)))
{
return(-3);
}
my($oldfh) = select(MAIL);
$| = 1;
select($oldfh);
$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-4);
}
print MAIL "helo $SMTP_SERVER\r\n";
$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-5);
}
print MAIL "mail from: <$fromaddr>\r\n";
$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-5);
}
foreach (split(/, /, $to))
{
print MAIL "rcpt to: <$_>\r\n";
$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-6);
}
}
print MAIL "data\r\n";
$_ = <MAIL>;
if (/^[45]/)
{
close MAIL;
return(-5);
}
}
if ($SEND_MAIL ne "")
{
open (MAIL,"| $SEND_MAIL");
}
print MAIL "To: $to\n";
print MAIL "From: $fromaddr\n";
print MAIL "Reply-to: $replyaddr\n" if $replyaddr;
print MAIL "X-Mailer: Perl Powered Socket Mailer\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message";
print MAIL "\n.\n";
if ($SMTP_SERVER ne "")
{
$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-7);
}
print MAIL "quit\r\n";
$_ = <MAIL>;
}
close(MAIL);
return(1);
}
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Sun, 29 Aug 1999 08:52:58 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Pattern Matching
Message-Id: <37c8ebf7.893410@news.skynet.be>
Abigail wrote:
>() print "\Q$pattern\E";
>()
>() will insert them (only) where necessary, for you.
>
>
> $pattern = ";";
> print "\Q$pattern\E";
>
>How `necessary' is that backslash?
You're right, of course. What I ment was that it would not ever put a
backslash where it wouldn't be acceptable, like in
$pattern = "s";
>Note that the \E isn't needed in this case.
No. But it's a good habit. It doesn't hurt.
--
Bart.
------------------------------
Date: Sat, 28 Aug 1999 23:15:19 -0700
From: Lee Fesperman <firstsql@ix.netcom.com>
Subject: Re: Perl Y2K Bugs on the Internet
Message-Id: <37C8CFF7.2DD3@ix.netcom.com>
Joe Wright wrote:
>
> Why do you suppose tm_year is deficient? It is an int. It won't roll
> over from 99 to 00.
tm_year is a poor design. It produces date displays like,
Jan 1, 100 and Jan 1, 19100
It is conducive to errors. *All* programmers make errors.
--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
------------------------------
Date: Sat, 28 Aug 1999 23:21:53 -0700
From: Lee Fesperman <firstsql@ix.netcom.com>
Subject: Re: Perl Y2K Bugs on the Internet
Message-Id: <37C8D181.2D99@ix.netcom.com>
Bart Lateur wrote:
>
> Lee Fesperman wrote:
>
> >In reality, this date 'feature' is a weakness in Perl (and C, Javascript, ...) -
> > a poor design. ... Java has this
> >deficiency but has recognized it, replaced it with a correct implementation and
> >deprecated the problematic stuff.
>
> How on earth can you "correct the implementation" without loosing
> backward compatibility? By adding another function? I think that's why
> Perl people object to this addition, which would make the perl
> executable bigger: because it's so easy to compensate. All you have to
> do is to add 1900 to the year.
I agree it's not a very good solution. The situation is Java is mixed, some APIs still
require the deprecated class. However, adding a less error-prone function would make
things easier, and I doubt the cost to the Perl executable would be that big.
--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
------------------------------
Date: Sun, 29 Aug 1999 09:32:21 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: regex bug: (?:\d{3})+ loses count
Message-Id: <37cefc90.5143231@news.skynet.be>
Can somebody confirm or deny this is indeed a bug, or that it has been
fixed already. I've tried this on the latest (?) ports of Activestate
(MSWin32) and DJGPP (dos) (both 5.005). It looks like the {n} modifier
looses count if it's inside a (?:...) construct, followed by a '*', '+'
or '?' modifier.
I stumbled across it when I tried to roll my own "commify" code. (This
version only "works" for integers.)
#! perl -w
$_ = '1234567890';
($good = $_) =~ s/(\d)(?=(?:\d\d\d)+(?!\d))/$1,/g;
print "Good: $good\n";
($bad = $_) =~ s/(\d)(?=(?:\d{3})+(?!\d))/$1,/g;
print "Bad: $bad\n";
($ugly = $_) =~ s/(\d)(?=(?:\d{3})(?:\d{3})*(?!\d))/$1,/g;
print "Ugly: $ugly\n";
-->
Good: 1,234,567,890
Bad: 1,2,3,4,5,6,7,8,9,0
Ugly: 1,2,3,4,5,6,7,890
IMO, it should give the same result for all three. Why would '\d\d\d'
give different results than '\d{3}'?
This one is fun (but equally wrong), too:
($ugly = $_) =~ s/(\d)(?=(\d{3})(\d{3})*(?!\d))/$1,/g;
print "Ugly: $ugly\n";
-->
Ugly: 1,2,3,4,567,890
p.s. I can't use perlbug, because I can't mail from within perl. The
script simply dies. Bloody scripts... ;-)
--
Bart.
------------------------------
Date: Sun, 29 Aug 1999 14:54:59 +0800
From: Andriani Siau <andriani@singnet.com.sg>
Subject: run perl by browser
Message-Id: <37C8D942.8BFCB5DC@singnet.com.sg>
hi guys, sorry to disturb you.
i can run my program with command line but when i tried to invoke my
program using html( post method) to submit the form data, it doesn't
work. and the browser ask me whether i want to download file. i run my
program in PC using windows 98.
i have tried to find the answer in FAQ but i couldn't solve my problem
thank you in advance
bye
andriani
------------------------------
Date: Sun, 29 Aug 1999 17:52:36 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: run perl by browser
Message-Id: <MPG.123391d26c26c061989c96@news-server>
Andriani Siau writes ..
>i can run my program with command line but when i tried to invoke my
>program using html( post method) to submit the form data, it doesn't
>work. and the browser ask me whether i want to download file. i run my
>program in PC using windows 98.
>i have tried to find the answer in FAQ but i couldn't solve my problem
you are trying to open the file with your browser .. you need to
actually have a web server installed and connect to that web server ..
the Perl program will then run as a CGI program and your browser will be
given the results
how to install a web server and all that other crap is left as an
exercise for the reader (or as a question to another newsgroup)
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: 29 Aug 1999 03:57:15 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: unicode and perl
Message-Id: <slrn7shtkt.23d.abigail@alexandra.delanet.com>
chris jaffe (goatholl@sonic.net) wrote on MMCLXXXIX September MCMXCIII in
<URL:news:37C89446.B7E5E997@sonic.net>:
`` how do I use unicode with perl?
Get a developments version, and use UTF8.
Abigail
--
perl -wle '$, = " "; print grep {(1 x $_) !~ /^(11+)\1+$/} 2 .. shift'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 29 Aug 1999 06:49:04 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: Will you help me solve this
Message-Id: <37c8d7e0$0$17161@nntp1.ba.best.com>
jp_48504@yahoo.com wrote:
> I am sure that this is a simple problem to most of you, but i am still
> very much an infant when it comes to perl. This is my problem: I have
> a program that is to figure out some totals, but it will print out a
> number like 32.0746153846154 what I want it to do is to round it to the
> nearest tenth such as 32.1 for this number. Can anyone help me with
> this. I really do appreciate it.
You want either printf (to print out the number) or sprintf (to return
it as a string you can assign to a variable). Each is used the same
way: printf (plus an optional filehandle) (or sprintf), followed by a
string that can contain both literal text and some special formatting
codes, followed by a list of one or more values (or variables that
contain those values) that will be plugged into the string according to
the instructions embodied in those formatting codes.
This has been one of the harder things for me to pick up as I work
through my own Perl newbie-hood. Historically these functions weren't
documented very well in the Perl docs (at least for someone not
familiar with the C functions of the same name, from which they take
their syntax); now there's a fairly complete explanation in the
perlfunc manpage under sprintf, but it's still pretty rough going for
someone completely unfamiliar with it, and could benefit from a few
examples, maybe, at least for dweebs like me.
Anyway, the formatting code you want to use is probably something like
'%.1f', which will format the value you plug into it as a floating
point number with one digit to the right of the decimal place. So you
could use something like:
$num = 32.0746153846154;
printf '%.1f', $num;
which would print out the string '32.1'.
Here are some more examples, just for kicks:
printf '%4u', 4; # prints ' 4'
printf '%04u', 4; # prints '0004'
printf '%-4u', 4; # prints '4 '
printf '%1.1f%%', 12.73; # prints '12.7%'
printf 'Cost: $%1.2f', 14.5; # prints 'Cost: $14.50'
printf '%10s %10s', 'walnuts', 'acorns';
# prints ' walnuts acorns'
printf '%-10s %10.3s', 'walnuts', 'acorns';
# prints 'walnuts aco'
$item = 'bread';
$cost = 1.59235;
printf "The cost of $item is \$%1.2f", $cost;
# prints 'The cost of bread is $1.59'
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
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 672
*************************************