[14072] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1482 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 24 18:10:43 1999

Date: Wed, 24 Nov 1999 15:10:29 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <943485029-v9-i1482@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 24 Nov 1999     Volume: 9 Number: 1482

Today's topics:
    Re: New dialect of perl: xperl (or reinventing perl, or (Abigail)
    Re: Newbie: Hash question (Brett W. McCoy)
    Re: Percentages Question (Abigail)
    Re: Perl and Linux <peter@berghold.net>
        Perl interact with Unix command <eastwoodch@yahoo.com>
    Re: Perl interact with Unix command <durbin@cig.mot.com>
    Re: Perl interact with Unix command <nandu@cimedia.com>
    Re: Printing on LPT1 or COM1 on NT Perl <dchristensen@california.com>
        Redirect question. <webmaster@webdream.com>
    Re: Redirect question. <flavell@mail.cern.ch>
    Re: Redirect question. (Abigail)
    Re: reg expr question <sariq@texas.net>
    Re: remove html codes ? (Craig Berry)
    Re: Search Engine <peter@berghold.net>
        Sockets and TCP/UDP packets <amonotod@netscape.net>
    Re: Sockets and TCP/UDP packets <mccloskey1.spamkills@home.com>
    Re: sprintf help <sariq@texas.net>
    Re: sprintf help <skilchen@swissonline.ch>
    Re: sprintf help (Simon Cozens)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 24 Nov 1999 13:31:54 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: New dialect of perl: xperl (or reinventing perl, or perl-izing jpython)
Message-Id: <slrn83offc.m2v.abigail@alexandra.delanet.com>

Benjamin Franz (snowhare@long-lake.nihongo.org) wrote on MMCCLXXVI
September MCMXCIII in <URL:news:1NV_3.225$Wo6.3632@typhoon01.swbell.net>:
-- In article <slrn83o40s.m2v.abigail@alexandra.delanet.com>,
-- Abigail <abigail@delanet.com> wrote:
-- >I'm familiar with the trick. The trick requires extra work, and it requires
-- >cooperation *DONE IN ADVANCE*. It's making easy things hard. It's not
-- >Perl. It's anti-Perl.
--
-- Yes, but using 'base' 'Class::' constructors rather than always
-- rolling your own would make it easy.
--
-- package MyOwnClass;
-- use base qw(Class::ImprovedNamedParms);
-- sub new {
--     my $proto = shift;
--     my $class = ref ($proto) || $proto || __PACKAGE__;
--     my $self  = SUPER::new({ -class => $class,
--                          -namespace => __PACKAGE__,
--                        -legal_parms => [qw(-named_parm -another_named_parm)],
--                        -init_values => [@_],
--                         });
--     $self;
-- }


My goodness. Just to create a simple object. And people claim Java is
difficult.

How's this supposed to work if you want to subclass Foo? (Note, modifying
Foo is out of the question - we're talking about software re*use*, not
software re*write*.


Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


  -----------== 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: Wed, 24 Nov 1999 20:55:45 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: Newbie: Hash question
Message-Id: <slrn83okbe.g0r.bmccoy@moebius.foiservices.com>

Also Sprach dan_simser@my-deja.com <dan_simser@my-deja.com>:

>but what I want to do is instead of creating a section of code like
>above for each field, I would like to have a loop.
>
>Each uploaded file has a variable name $p1_photo...$p15_photo/
>$org_photo1...$org_photo15.

Why don't you use arrays?  If you want to index on a group of variables
numbered sequentially with a loop, put them all into an array.

-- 
Brett W. McCoy                             bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek)   http://www.foiservices.com
FOI Services, Inc./DIOGENES                301-975-0110
---------------------------------------------------------------------------


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

Date: 24 Nov 1999 13:34:47 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Percentages Question
Message-Id: <slrn83ofko.m2v.abigail@alexandra.delanet.com>

David Cassell (cassell@mail.cor.epa.gov) wrote on MMCCLXXVI September
MCMXCIII in <URL:news:383C2847.8AC74246@mail.cor.epa.gov>:
'' Abigail wrote:
'' > 
'' > Larry Rosler (lr@hpl.hp.com) wrote on MMCCLXXVI September MCMXCIII in
'' > <URL:news:MPG.12a4e16364478f9098a266@nntp.hpl.hp.com>:
'' [snip]
'' >         $avg = do {local $" = "+"; eval ("@x") / @x};
'' > 
'' > // I am sure you realize that this is both slow and EEE-vil.
'' > 
'' > Yeah, but being evil puts me opposite to Barney, so that isn't too bad.
'' 
'' Ummm, from this I deduce that you have no small children.

Not anymore. They all went on the BBQ.

'' Barney is evil.  With a capital 'E'.  Even more evil than your
'' most ingenious code.


You mean, you don't love Barney?



Abigail
-- 
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi


  -----------== 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: Wed, 24 Nov 1999 19:31:05 GMT
From: "Peter L. Berghold" <peter@berghold.net>
Subject: Re: Perl and Linux
Message-Id: <Pine.LNX.3.96.991124142828.2881H-100000@uboat.berghold.net>



On Sun, 21 Nov 1999, Henner Graubitz wrote:

> Is it possible that these people can send me their httpd.conf,
> srm.conf and access.conf as an attachement to my e-mail address 
> 

Are you on crack?  First, this is way off topic and second, I ain't about
to send my config files to someone I don't know.

Try the comp.infosystems.* newsgroups *or* http://www.apache.org's online
documentation.

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Peter L. Berghold                        Peter@Berghold.Net
"Linux renders ships                     http://www.berghold.net
 NT renders ships useless...."           ICQ# 11455958





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

Date: Thu, 25 Nov 1999 03:14:33 +0800
From: Scootty <eastwoodch@yahoo.com>
Subject: Perl interact with Unix command
Message-Id: <383C3919.B6ECB6E4@yahoo.com>

Hi

I will like to write perl CGi-Script that let the users can be
update/change the password of the unix system from the browser. But I
don't know how to put the
value typed from the net to passwd command which will ask you new pass
and
then type again in comfirm.

Thanks



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

Date: Wed, 24 Nov 1999 15:58:34 -0600
From: Chris Durbin <durbin@cig.mot.com>
Subject: Re: Perl interact with Unix command
Message-Id: <Pine.GSO.4.21.9911241556170.19723-100000@ballad>

On Thu, 25 Nov 1999, Scootty wrote:

:)Hi
:)
:)I will like to write perl CGi-Script that let the users can be
:)update/change the password of the unix system from the browser. But I
:)don't know how to put the
:)value typed from the net to passwd command which will ask you new pass
:)and
:)then type again in comfirm.

Try using the Expect module from CPAN

:)
:)Thanks
:)
You're welcome

-- 
Chris Durbin           Motorola, Cellular Infrastructure Group
--------------------------------------------------------------
Phone: (847)435-9558           Pager: 1-800-759-8888, #1268222
Fax:   (847)632-4552           Email:       durbin@cig.mot.com



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

Date: 24 Nov 1999 16:47:35 -0500
From: Nandu Shah <nandu@cimedia.com>
Subject: Re: Perl interact with Unix command
Message-Id: <m3bt8j36ko.fsf@budgie.cimedia.com>

Scootty <eastwoodch@yahoo.com> writes:

> I will like to write perl CGi-Script that let the users can be
> update/change the password of the unix system from the browser. 

Wow, what a coincidence.  Someone who sounds a lot like you and has
the same email address as you asked a very similar question just a
couple of days ago.  I'll tell you the same thing I told that person:

   Scootty <eastwoodch@yahoo.com> writes:

   > How to write the cgi script that using the command 'passwd' for 
   > users can change their password of unix system from the net?

   This is one of those cases when, if you don't know how to do it,
   you might consider it a highly dangerous thing to attempt.

   But, if you MUST do it, look to the 1st edition Camel Book (the
   pink one), p. 286 for advice.


Nandu


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

Date: Wed, 24 Nov 1999 13:15:25 -0800
From: "David Christensen" <dchristensen@california.com>
Subject: Re: Printing on LPT1 or COM1 on NT Perl
Message-Id: <383c5741_3@news5.newsfeeds.com>

Russ:

> Does any one know how to send prints directly to the printer either on
LPT1 or COM1.

For direct control of a serial port, you can use Win32::SerialPort from
CPAN.  Check the readme while you're there, as it depends upon another
module (Win32::API?).


David Christensen
dchristensen@california.com





  -----------== 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: Wed, 24 Nov 1999 20:55:32 GMT
From: "Craig Vincent" <webmaster@webdream.com>
Subject: Redirect question.
Message-Id: <8hY_3.588$lr4.558@198.235.216.4>

Let's say this is coming from http://hello.com/move.cgi

<snip>
print "Location: http://foobar.com/ \n\n";
</snip>

The redirection works like a charm...however the browser does not pass the
referring URL (ie. The HTTP_REFERER variable is blank...it doesn't have
http://hello.com/move.cgi as a referer).  Is there any way to pass there
referring URL when redirecting the browser?

--
Sincerely,

Craig Vincent
Senior Webmaster/Programmer
Web Dream Inc.






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

Date: Wed, 24 Nov 1999 22:55:11 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Redirect question.
Message-Id: <Pine.HPP.3.95a.991124224520.4103K-100000@hpplus01.cern.ch>

On Wed, 24 Nov 1999, Craig Vincent wrote:

> print "Location: http://foobar.com/ \n\n";
> </snip>

Even a brief perusal of this group (clpm) should have showed that CGI
questions (as opposed to Perl language questions, which this clearly is
not) are considered off-topic.  F'ups prophylactically set. 

You should also know that the group comp.lang.perl has been obsolete
for years, even if a few news providers don't seem to have noticed yet.

> The redirection works like a charm...however the browser does not pass the
> referring URL (ie. The HTTP_REFERER variable is blank...

The specification says something along the lines of the referer header
being optional anyway, so any design that absolutely relies on it being
present is broken.

>  Is there any way to pass there
> referring URL when redirecting the browser?

Not that I know of: clients (browsers etc.) do pretty much what they do
in this regard.

Maybe if you were to tell the CGI group what you're trying to achieve,
rather than giving a partial description of a non-working solution, 
someone might be able to suggest an alternative approach that works.

good luck



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

Date: 24 Nov 1999 17:03:41 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Redirect question.
Message-Id: <slrn83orsg.m2v.abigail@alexandra.delanet.com>

Craig Vincent (webmaster@webdream.com) wrote on MMCCLXXVI September
MCMXCIII in <URL:news:8hY_3.588$lr4.558@198.235.216.4>:
<> Let's say this is coming from http://hello.com/move.cgi
<> 
<> <snip>
<> print "Location: http://foobar.com/ \n\n";
<> </snip>
<> 
<> The redirection works like a charm...however the browser does not pass the
<> referring URL (ie. The HTTP_REFERER variable is blank...it doesn't have
<> http://hello.com/move.cgi as a referer).  Is there any way to pass there
<> referring URL when redirecting the browser?


The browser is free to send information. But this has nothing more to
do with Perl than roasting peanuts does.



Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


  -----------== 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: Wed, 24 Nov 1999 13:22:34 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: reg expr question
Message-Id: <383C3AFA.6C95AC58@texas.net>

Larry Rosler wrote:
> 
> In article <xjg903n51zv.fsf@gamora.ndhm.gtegsc.com> on Wed, 24 Nov 1999
> Well, gawrsh, I didn't invent it!
> 
> <QUOTE>
> Perl defines the following zero-width assertions:
> 
>     \b  Match a word boundary
>     \B  Match a non-(word boundary)
>     \A  Match only at beginning of string
>     \Z  Match only at end of string, or before newline at the end
>     \z  Match only at end of string
>     \G  Match only where previous m//g left off (works only with /g)
> </QUOTE>
> 

I'm not sure when \z was introduced.  But:

acme$ perl -v

This is perl, version 5.004_04 built for i686-linux

Copyright 1987-1997, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the GNU General Public License, which may be found in the Perl 5.0
source kit. 

<QUOTE>
Perl defines the following zero-width assertions:

   \b  Match a word boundary
   \B  Match a non-(word boundary)
   \A  Match at only beginning of string
   \Z  Match at only end of string (or before newline at the end)
   \G  Match only where previous m//g left off (works only with /g) 
</QUOTE>

Yet another reason why I try and I try to get our (corporate) perl
upgraded.  Sheesh, 'perldoc -q' alone makes the upgrade worthwhile.

- Tom


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

Date: Wed, 24 Nov 1999 19:06:50 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: remove html codes ?
Message-Id: <s3odqa8hrrp46@corp.supernews.com>

Hanzie (hanz@chello.nl) wrote:
: I'm coding some sort of newsgroup perl program. Is there any short code to
: remove any sort of HTML code from the user's input?

This is the F-est of FAQs.  Short answer:  Not really.  Medium answer:
You can kind of do it for well-formed HTML, but use HTML::Parser, not a
regex.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "They do not preach that their God will rouse them
      a little before the nuts work loose." - Kipling


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

Date: Wed, 24 Nov 1999 19:11:52 GMT
From: "Peter L. Berghold" <peter@berghold.net>
Subject: Re: Search Engine
Message-Id: <Pine.LNX.3.96.991124140338.2881E-100000@uboat.berghold.net>




On Sat, 20 Nov 1999, Jaime Perez wrote:

> For those of you that are not helping me with the program, I would
> appreciate it if you kept

REALLY!!!   Sorry, I can't really take your claim seriously.  First off, I
went to your web link and looked at "your" code and found a line for line
duplication of code that was published recently in an article by Randall
Schwartz in a recent article in Web Techniques magazine. 

Considering who wrote it I doubt that there is anything wrong with the
code. You could have at least changed the line 

my $SITE="stonehenge.com"; 

to reflect you own web site.   Citing the original author would have been
nice too. 

> you go to comedy clubs.  This place is for professionals like me trying to
> find solutions for not so evident
> problems.
Professional what? Con Artist?  Give me a break! OBTW: I charge $125 an
hour for providing solutions to folks like you.

 ...  and I get it....


I normally don't flame people because I have a live and let live policy on
the net... but you managed to piss me off with this one...


-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Peter L. Berghold                        Peter@Berghold.Net
"Linux renders ships                     http://www.berghold.net
 NT renders ships useless...."           ICQ# 11455958




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

Date: Wed, 24 Nov 1999 21:35:53 GMT
From: amonotod <amonotod@netscape.net>
Subject: Sockets and TCP/UDP packets
Message-Id: <81hlnq$ecj$1@nnrp1.deja.com>

Hello all,
  I am in need of some examples on how to use network sockets, in
relation to building a TCP/UDP ping/tracert program.

  I have been ordered to put some kinda crap network monitoring agent on
my Solaris box.  The client connects to the remote monitoring server
just fine, but the server cannot connect back to the client.  The
problem may be a router issue, being that we are at different locations.
 However, we cannot prove this either way.  The firewall people say that
the firewall has been opened up to allow the packets both ways on both
ports needed, and that the routers are strictly routers, ie: they do no
port/packet filtering.

  So, who can show me how to make a ping/tracert that will use UDP to
check ports 9494 and 9495 on a remote machine?  Please keep in mind that
a tracert type of implementation is better, as we can test the port with
telnet.  Also, UDP is preferred...

  One more note:  Platform is not important, can be either Solaris/Unix
or Windows, but I posted here because Perl solution is preferred.

Thanks to all,
amonotod

P.S.
Happy Thanksgiving to all who celebrate, and Have a Good Day to all
others!


--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 24 Nov 1999 21:57:51 GMT
From: "Tim McCloskey" <mccloskey1.spamkills@home.com>
Subject: Re: Sockets and TCP/UDP packets
Message-Id: <zbZ_3.28976$zd.323887@news1.alsv1.occa.home.com>


not sure if this is even close, if not just trash it.....
http://cpan.valueclick.com/modules/by-category/05_Networking_Devices_IPC/Net
/Net-Traceroute-0.9.readme

amonotod <amonotod@netscape.net> wrote in message
news:81hlnq$ecj$1@nnrp1.deja.com...
| Hello all,
|   I am in need of some examples on how to use network sockets, in
| relation to building a TCP/UDP ping/tracert program.
|
|   I have been ordered to put some kinda crap network monitoring agent on
| my Solaris box.  The client connects to the remote monitoring server
| just fine, but the server cannot connect back to the client.  The
| problem may be a router issue, being that we are at different locations.
|  However, we cannot prove this either way.  The firewall people say that
| the firewall has been opened up to allow the packets both ways on both
| ports needed, and that the routers are strictly routers, ie: they do no
| port/packet filtering.
|
|   So, who can show me how to make a ping/tracert that will use UDP to
| check ports 9494 and 9495 on a remote machine?  Please keep in mind that
| a tracert type of implementation is better, as we can test the port with
| telnet.  Also, UDP is preferred...
|
|   One more note:  Platform is not important, can be either Solaris/Unix
| or Windows, but I posted here because Perl solution is preferred.
|
| Thanks to all,
| amonotod
|
| P.S.
| Happy Thanksgiving to all who celebrate, and Have a Good Day to all
| others!
|
|
| --
|     `\|||/                     amonotod@
|       (@@)                     netscape.net
|   ooO_(_)_Ooo________________________________
|   _____|_____|_____|_____|_____|_____|_____|_____|
|
|
| Sent via Deja.com http://www.deja.com/
| Before you buy.



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

Date: Wed, 24 Nov 1999 14:05:58 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: sprintf help
Message-Id: <383C4526.B8BD4CC3@texas.net>

Samuel Kilchenmann wrote:
> 
> In article <slrn83nm2s.gfs.simon@othersideofthe.earth.li>,
>   simon@brecon.co.uk wrote:
> > esalmon@packet.net (comp.lang.perl.misc):
> > >How would I round up a scallar using the sprintf format?
> > >     $weight = 2.25
> > >     $rounded_up = sprintf("?????", $weight);
> > >$weight should = 3
> >
> > perldoc -q round
> >
> > Makes you think the FAQ was written for a reason, doesn't it?
> >
> Please, please, please: Show me, how you do round up with sprintf or
> anything else mentioned in the FAQ ...

Ummm...

perlfaq4: 'Does Perl have a round() function? What about ceil() and
floor()? Trig functions?'

You're welcome, you're welcome, you're welcome.

Makes you think the FAQ was written for a reason, doesn't it?

HTH.  HAND.

- Tom


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

Date: Wed, 24 Nov 1999 23:15:41 +0100
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: sprintf help
Message-Id: <81ho75$1ru6t$1@fu-berlin.de>

Larry Rosler <lr@hpl.hp.com> wrote in message
news:MPG.12a5c753899c3d7798a277@nntp.hpl.hp.com...
> In article <81h4u5$1b9$1@nnrp1.deja.com> on Wed, 24 Nov 1999
16:49:10
> GMT, Samuel Kilchenmann <skilchen@swissonline.ch> says...
> > In article <slrn83nm2s.gfs.simon@othersideofthe.earth.li>,
> >   simon@brecon.co.uk wrote:
> > > esalmon@packet.net (comp.lang.perl.misc):
> > > >How would I round up a scallar using the sprintf format?
> > > > $weight = 2.25
> > > > $rounded_up = sprintf("?????", $weight);
> > > >$weight should = 3
> > >
> > > perldoc -q round
> > >
> > > Makes you think the FAQ was written for a reason, doesn't it?
> > >
> > Please, please, please: Show me, how you do round up with sprintf
> > or anything else mentioned in the FAQ ...
>
> Er, umm, you read the FAQ.  The clue is even in the title.  Here's
> how the FAQ begins:
>
I know, but this is not one of the best FAQ entries. How could
somebody who doesn't know already what floor and ceil do, guess that
these functions may be used to round up or down? The following
examples don't help very much:
>     $ceil   = ceil(3.5);                        # 4
>     $floor  = floor(3.5);                       # 3
>
How do you deduce from these examples that ceil(3.1) == 4, ceil(-3.1)
== -3, floor(3.9) == 3 and floor(-3.9) == -4 if you don't know that
already? IMHO it's a mistake to use the "special case" number 3.5 in
this context.

And the description in "perldoc POSIX" is a little bit silly:
ceil    This is identical to the C function `ceil()'.
floor   This is identical to the C function `floor()'.

K&R don't need many more characters to provide an understandable
description of these functions:
ceil(x)   smallest integer not less than x, as a double.
floor(x)  largest integer not greater than x, as a double.

A book like K&R (The C Programming Language) is surely a very useful
complement to the Perl documentation.

A more verbose implementation of what Alex Rhomberg already posted
might look like:
#!perl -w
use strict;

sub round_up {
  my $n = shift;

  my $i = int($n);
  my $result;

  if ($i == $n) {
    $result = $n;
  } else {
    if ($n < 0) {
      $result = $i;
    } else {
      $result = $i + 1;
    }
  }
  return $result;
}

sub round_down {
  my $n = shift;

  my $i = int($n);
  my $result;

  if ($n == $i) {
    $result = $n;
  } else {
    if ($n < 0) {
      $result = $i - 1;
    } else {
      $result = $i;
    }
  }
  return $result;
}

(Finally: i still hope that Perl will get a builtin round function
with the same rounding mode on all platforms where Perl is available.)




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

Date: 24 Nov 1999 22:36:59 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: Re: sprintf help
Message-Id: <slrn83oq4b.e4n.simon@othersideofthe.earth.li>

Samuel Kilchenmann (comp.lang.perl.misc):
>I know, but this is not one of the best FAQ entries. How could
>somebody who doesn't know already what floor and ceil do, guess that
>these functions may be used to round up or down?

You wanted to round a number with sprintf. The FAQ says:

       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

Tricky?

-- 
Be warned that typing killall "name" may not have the desired
effect on non-Linux systems, especially when done by a privileged user.
(From the killall manual page)


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 1482
**************************************


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