[24372] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6561 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 14 03:05:41 2004

Date: Fri, 14 May 2004 00: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           Fri, 14 May 2004     Volume: 10 Number: 6561

Today's topics:
    Re: "Definitive Guide to OOP in Perl"? <jwillmore@remove.adelphia.net>
        accessing Windows 64bit registry <erwin.jussli@t-online.de>
    Re: Anything better than ExtUtils::MakeMaker ? <Jon.Ericson@jpl.nasa.gov>
    Re: Datetime overflow with DBI ODBC setting 19th centur <jwillmore@remove.adelphia.net>
    Re: Need Perl Equivalent for C ioctl Functions for Mode <hal@thresholddigital.com>
    Re: Password scheme/Persistent session... <jwillmore@remove.adelphia.net>
    Re: Perldoc versus Man <notvalid@email.com>
    Re: Perldoc versus Man <jwillmore@remove.adelphia.net>
    Re: Perldoc versus Man <uri@stemsystems.com>
    Re: Perldoc versus Man <notvalid@email.com>
        Problem with jabberd-1.4.2, xdb_auth_cpile.smb and Jabb (tylernt)
        Random Integer <lepor5e@bestweb.net>
    Re: Random Integer <uri@stemsystems.com>
    Re: Random Integer <spamtrap@dot-app.org>
    Re: Random Integer <bigiain@mightymedia.com.au>
        RegEx to delete // comments NOT in quotes: ( ' ) OR (") <NewsGroups@US-Webmasters.com>
    Re: RegEx to delete // comments NOT in quotes: ( ' ) OR <wherrera@lynxview.com>
        Rounding a Number <lepor5e@bestweb.net>
    Re: Rounding a Number <uri@stemsystems.com>
    Re: Rounding a Number <spamtrap@dot-app.org>
    Re: Rounding a Number <dha@panix.com>
    Re: Rounding a Number <bigiain@mightymedia.com.au>
    Re: Stopping code execution in RE's <mb@uq.net.au.invalid>
    Re: Stopping code execution in RE's <usenet@morrow.me.uk>
    Re: Why Carp::croak over die? <nomail_please@nomail.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 14 May 2004 00:48:30 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: "Definitive Guide to OOP in Perl"?
Message-Id: <pan.2004.05.14.04.48.28.925659@remove.adelphia.net>

On Thu, 13 May 2004 18:25:44 +0000, Randal L. Schwartz wrote:

>>>>>> "kj" == kj  <socyl@987jk.com> writes:
> 
> kj> P.S. I already own a copy of Conway' "Object Oriented Perl", which
> kj> I think is pretty good, but I find the subject inexhaustible.
> 
> For a more tutorial approach, have you seen my "Learning Perl Objects
> References and Modules", the sequel in spirit and form to "Learning Perl"?

<shamless plug>
I found the book to be excellent.  Conway's book is the in depth
examination of OOP, but Randal's is a "hit the ground running" examination
of references, objects, and OOP (Oh, my!).  Job well done!
</shameless plug>

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 We wish you a Hare Krishna We wish you a Hare Krishna We wish
 you a Hare Krishna And a Sun Myung Moon!   -- Maxwell Smart 
 


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

Date: Fri, 14 May 2004 02:36:57 +0200
From: "Erwin Jussli" <erwin.jussli@t-online.de>
Subject: accessing Windows 64bit registry
Message-Id: <c8148r$gkm$1@online.de>

Hi NG,

I am using TieRegistry to access the registries of WinNT,
Win2000, WinXP and Win2003 to find out the installed
patches and hotfixes.

What is working well with 32 bit is not working with 64 bit,
i.e. I am having problems to access the registry of an IA64
system with Win2003.

Does anyone have any hint for me ?

Thanks and best regards,
Erwin




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

Date: Thu, 13 May 2004 16:30:23 -0700
From: Jon Ericson <Jon.Ericson@jpl.nasa.gov>
Subject: Re: Anything better than ExtUtils::MakeMaker ?
Message-Id: <rcgad0bhpm8.fsf@Jon-Ericson.sdsio.prv>

Irving Kimura <irving_kimura@lycos.com> writes:

> I don't know how much truth there is to all of this, but I have to
> say that I find ExtUtils::MakeMaker inflexible and all-around
> difficult to use.  Is there anything better out there?

Module::Build claims to be a replacement for ExtUtils::MakeMaker.

Jon


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

Date: Fri, 14 May 2004 00:44:21 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Datetime overflow with DBI ODBC setting 19th century dates with placeholders
Message-Id: <pan.2004.05.14.04.44.19.763862@remove.adelphia.net>

On Thu, 13 May 2004 18:00:20 +0100, iain wrote:

[ ... ]
> Any ideas for correction or workaround?
> 
> Example, using a table called Patients, which has a field called DOB,
> type datetime.....
> 
> use DBI;
> use strict;
> my $dbserver="Myserver"; my $dbdatabase="MyDB"; my $dbWinAuth=1; my
> $dsn="driver={SQL
> Server};SERVER=$dbserver;DATABASE=$dbdatabase;trusted_connection=yes";
> 
> my $dbh = DBI->connect("dbi:ODBC:$dsn") or die "cannot connect to
> database: $DBI::errstr  \n";
> $dbh->{AutoCommit}=1;
> 
> my $sth = $dbh->prepare("update Patients set DOB=? where PatientID=10");
> 
> $sth->execute('1900-01-01');  # works OK $sth->execute('1799-12-31');  #
> gives error

First ... try to insert the date using the command line utility for the
RDBMS.  If it works, then it *should* work in the script.  If it doesn't,
then the issue lies with the RDBMS.

Next, you could use the 'debug' function in the DBI module to see what the
"conversation" is between the script and the database.  That will shed
some light on why it's not working as expected.

There are more ideas, but give these a try first :-)

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 "They make a desert and call it peace."   -- Tacitus (55?-120?) 
 
 


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

Date: Thu, 13 May 2004 22:57:10 GMT
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Need Perl Equivalent for C ioctl Functions for Modem Control
Message-Id: <a3Toc.4398$6f5.311777@attbi_s54>

Thank you so much!  Not knowing C, I had no idea where to look next.  This
is a big help, especially since it points me to where I can explore for
more info!

Hal

Jim Gibson wrote:

> In article <nyPoc.2020$Dz.162996@attbi_s52>, Hal Vaughan
> <hal@thresholddigital.com> wrote:
> 
>> I have a problem with my mode, which I am controlling from
> 
> [...]
> 
>> 
>> Here's the part of the C code that gets the modem info:
>> 
>>   tcgetattr(fd, &savetty);
>>   ioctl(fd, TIOCGETP, &sg);
>>   ioctl(fd, TIOCGETC, &tch);
>>   ioctl(fd, TIOCLGET, &lsw);
>>   ioctl(fd, TIOCMODG, &m_word);
>>   
>> And here's the part that restores it when I exit minicom:
>> 
>>   tcsetattr(fd, TCSANOW, &savetty);
>>   ioctl(fd, TIOCSETP, &sg);
>>   ioctl(fd, TIOCSETC, &tch);
>>   ioctl(fd, TIOCLSET, &lsw);
>>   ioctl(fd, TIOCMODS, &m_word);
>> 
>> From my understanding, ioctl is changing the settings on the modem.
> 
> tcsetattr and ioctl are changing settings in the terminal driver, not
> the modem. There is very limited direct control of a modem, which is
> probably attached to your computer via an RS-232 interface. Your
> computer normally controls the modem by sending characters to it over
> the serial line using "AT" commands.
> 
>> I
>> figure if I knew what it was changing, I could make sure I set it to what
>> works for my Perl script in that script.  I'm not clear if "tcgetattr" is
>> storing the ENTIRE modem configuration or not.
> 
> tcgetattr is saving the contents of the termios structure. See man 4
> termios and /usr/include/sys/termois.h for details (if you are on a
> unix system).
> 
>> It would help to know if it
>> does.  Also knowing what is being changed in the ioctl calls (TIOCSETP,
>> TIOCSETC, TIOCLSET, TIOCMODS) would help, too.
> 
> The first four calls to ioctl are getting and saving the parameters,
> special characters, local modes, and modem control state (see ioctl.h,
> ioctl_compat.h, or ttycom.h). The next four are restoring these same
> values. What exactly these are, I do not know.
> 
>> Can anyone tell me what the
>> program is doing or what settings would be the equivalent in working with
>> the modem in Device::SerialPort?  While there are web pages with these
>> terms mentioned, they are always used in the context of people who
>> already know about them.
> 
> See "Advanced Programming in the UNIX Environment" by W. Richard
> Stevens for an explanation of what some of the flags mean.



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

Date: Fri, 14 May 2004 01:04:16 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Password scheme/Persistent session...
Message-Id: <pan.2004.05.14.05.04.13.954917@remove.adelphia.net>

On Thu, 13 May 2004 11:46:20 -0700, krakle wrote:

> I'm creating members only service with perl (I will be using mod_perl)
> for a busy web site. I need to create a Members Area that is pass
> protected.
> 
> Originally I wanted to generate a random SID upon logging in and storing
> the SID in mySQL and also creating a cookie on the users computer to
> 'keep the user logged in'. However, I was told using cookies may not be
> a good idea. So the idea of storing the SID in the URL or hidden inputs
> arised. I really do not want to do this.
> 
> Is there anyways I can implement a password protected members area with
> perhaps a persistent session without the use of cookies? Any
> implementation ideas? I've seen sites like FaceTheJury.com which
> validates a login and they don't have SIDs in the URL or cookies created
> for this purpose.

http://www.stonehenge.com/merlyn/WebTechniques/col61.html

This article gives an overview of using *a* cookie for session management.
 The idea is to "tie" the browser to the session, thus giving some
 persistence.  You could use a cokkie to associate the browser with the
 sesion and use a database on the back end to store "stuff" like username
 and password for the session's database connection.

Cookies, IMO, are about as secure a method (along with SSL and setting the
cookie to be secure) as you're going to get - short of true TCP connection
(think ssh). Web browsers are a wonderful gift to technology, but they are
one of the biggest headaches as far as security is concerned.

[ ... ]

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 Nasrudin walked into a teahouse and declaimed, "The moon is more
 useful than the sun."  "Why?", he was asked.  "Because at night 
 we need the light more." 


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

Date: Fri, 14 May 2004 04:56:30 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Perldoc versus Man
Message-Id: <2kYoc.67050$5j.33346@newssvr25.news.prodigy.com>

Uri Guttman wrote:
> and there are many man reader programs (i like tkman (if only
> it were written in perl!))

Shouldn't be too hard to duplicate using Tk. But, I seem to recall that 
it has already been done. A quick search on CPAN comes up with Tk::Pod, 
but that's not a standalone program.

--Ala



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

Date: Fri, 14 May 2004 01:11:29 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Perldoc versus Man
Message-Id: <pan.2004.05.14.05.11.27.214136@remove.adelphia.net>

On Fri, 14 May 2004 04:56:30 +0000, Ala Qumsieh wrote:

> Uri Guttman wrote:
>> and there are many man reader programs (i like tkman (if only
>> it were written in perl!))
> 
> Shouldn't be too hard to duplicate using Tk. But, I seem to recall that 
> it has already been done. A quick search on CPAN comes up with Tk::Pod, 
> but that's not a standalone program.

Huh?  tkpod works for me :-)  It's part of the Tk::Pod install.

It's not quite as functional as perldoc, but it's a pretty good tool.

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 "I may not be totally perfect, but parts of me are excellent."  
 -- Ashleigh Brilliant 
 


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

Date: Fri, 14 May 2004 05:22:49 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Perldoc versus Man
Message-Id: <x7ekpna8gq.fsf@mail.sysarch.com>

>>>>> "JW" == James Willmore <jwillmore@remove.adelphia.net> writes:

  JW> On Fri, 14 May 2004 04:56:30 +0000, Ala Qumsieh wrote:
  >> Uri Guttman wrote:
  >>> and there are many man reader programs (i like tkman (if only
  >>> it were written in perl!))
  >> 
  >> Shouldn't be too hard to duplicate using Tk. But, I seem to recall that 
  >> it has already been done. A quick search on CPAN comes up with Tk::Pod, 
  >> but that's not a standalone program.

  JW> Huh?  tkpod works for me :-)  It's part of the Tk::Pod install.

  JW> It's not quite as functional as perldoc, but it's a pretty good tool.

well that only does pod (i assume). tkman uses a program called rosetta
to handle many man formats and texinfo. lots of features including
integration with glimpse, a full text search engine. i have to redo it
one day but i used to have it setup with glimpse. you could update the
index from the tool itself.

so a tcl/tk to perl/tk translator is needed. :)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 14 May 2004 05:22:20 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Perldoc versus Man
Message-Id: <gIYoc.67061$LA.48757@newssvr25.news.prodigy.com>

James Willmore wrote:

> On Fri, 14 May 2004 04:56:30 +0000, Ala Qumsieh wrote:
> 
> 
>>Uri Guttman wrote:
>>
>>>and there are many man reader programs (i like tkman (if only
>>>it were written in perl!))
>>
>>Shouldn't be too hard to duplicate using Tk. But, I seem to recall that 
>>it has already been done. A quick search on CPAN comes up with Tk::Pod, 
>>but that's not a standalone program.
> 
> 
> Huh?  tkpod works for me :-)  It's part of the Tk::Pod install.
> 
> It's not quite as functional as perldoc, but it's a pretty good tool.

Cool. tkpod is listed under 'TODO' in the Tk::Pod pods. But, I never 
installed Tk::Pod, so I thought it wasn't implemented yet.

--Ala



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

Date: 13 May 2004 15:41:14 -0700
From: tylernt@yahoo.com (tylernt)
Subject: Problem with jabberd-1.4.2, xdb_auth_cpile.smb and Jabber::Connection
Message-Id: <f076244d.0405131441.192359f6@posting.google.com>

I'm afraid xdb_auth_cpile.pl isn't working with my Jabber server. It
worked ok in a small test environment but when I got more than, oh, 3
or 4 users logged on to the Jabber server, Jabber would get slower and
slower and eventually stop allowing logins and stop passing messages
after 1-5 minutes. It seemed to be related to someone trying to log in
with a bad username/password... the server seemed to die very quickly
after a failed login attempt was logged in record.log. Sometimes, the
xdb_auth_cpile.pl process would die, other times it would keep
running.

I noticed sometimes when I stopped the unresponsive jabberd, I would
get this:

Use of uninitialized value in concatenation (.) or string at
/usr/lib/perl5/site_perl/5.8.0/Jabber/Connection.pm line 416.

Use of uninitialized value in subroutine entry at
/usr/lib/perl5/site_perl/5.8.0/i386-linux/XML/Parser/Expat.pm line
614.

I started out with Jabber::Connection 0.03 but encountered problems
with jabberd segfaulting (the 'memory leak issue', presumably), so I
switched to 0.04, which caused the above problem.

I'm running jabberd-1.4.2 and using xdb_auth_cpile to authenticate
against a Win2k AD domain with smb. Jabberd worked fine prior to the
upgrade to xdb_auth_cpile.

Any ideas or suggestions?


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

Date: Thu, 13 May 2004 23:57:21 -0400
From: "Mike Lepore" <lepor5e@bestweb.net>
Subject: Random Integer
Message-Id: <10a8grkplosg485@corp.supernews.com>

The rand function generates a random number between 0 and 1.
Does someone have a subroutine I can use to generate a
random integer between 0 and integer n, inclusive?
Thank you.

--

Mike Lepore - Email delete the 5





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

Date: Fri, 14 May 2004 04:01:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Random Integer
Message-Id: <x7r7tnac8s.fsf@mail.sysarch.com>

>>>>> "ML" == Mike Lepore <lepor5e@bestweb.net> writes:

  ML> The rand function generates a random number between 0 and 1.
  ML> Does someone have a subroutine I can use to generate a
  ML> random integer between 0 and integer n, inclusive?

hmmm, how hard can this be? do you know basic math? have you read the
docs on rand to see what it really does (hint: it can generate numbers >
1)? what code have you tried yet?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 14 May 2004 00:11:12 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Random Integer
Message-Id: <ub2dndclopN92znd4p2dnA@adelphia.com>

Mike Lepore wrote:

> The rand function generates a random number between 0 and 1.

That's not what 'perldoc -f rand' says. Perhaps you should read that, and
find out what rand() *really* returns.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Fri, 14 May 2004 14:46:31 +1000
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: Random Integer
Message-Id: <bigiain-AEC158.14463114052004@individual.net>

In article <10a8grkplosg485@corp.supernews.com>,
 "Mike Lepore" <lepor5e@bestweb.net> wrote:

> The rand function generates a random number between 0 and 1.

Errrmmm, not _really_, thats a special case of rand where you don't 
supply an aguement. rand(5) does _not_ generate "a random number between 
0 and 1"

> Does someone have a subroutine I can use to generate a
> random integer between 0 and integer n, inclusive?

how about 

$num=sprintf "%u",rand($n+1);

have a look at:

perldoc -f rand
perldoc -f sprintf

cheers,

big
-- 
'You know all those spasticated-looking hip-hop gestures involving
extended fingers and wrists cocked at odd angles which are intended to 
have a meaning to the effect of "Kinoath!" or "You have spoken wisely,
my friend."? I'm making one in your direction now...' Marko in aus.moto


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

Date: Fri, 14 May 2004 00:22:39 -0500
From: "W. D." <NewsGroups@US-Webmasters.com>
Subject: RegEx to delete // comments NOT in quotes: ( ' ) OR (")???
Message-Id: <40A4579F.7D4@US-Webmasters.com>

Hi Folks,

I am about to ship myself to a mental hospital!  Can't figure
out a regular expression to strip out comments that begin 
with double slashes "//" but are not contained in quotation 
marks, either single (') or double (").

Here is a bunch of sample text that I've been working on:
===================== Code Start ==========================
// Some comments that should be trashed

Code goes here;

$SomeVar = '// These comments should be left alone!';

/* Some more comments that will remain */

" // These comments should also be left alone "

# Hash/Pound sign comments should remain for now

More Code goes here

       { This code should stay // This comment should go
       }
=========================== Code End ===========================

This is one of my PHP regexs that DOESN'T work:

   $TheCode = preg_replace('#([^\n\r\'\"]|.*)//.*[\n\r]#', '',
$TheCode);

Does anyone know how to create a RegEx to do this????!

Thank you for saving my sanity if you can help!!!!!

-- 
Start Here to Find It Fast!™ ->
http://www.US-Webmasters.com/best-start-page/
$8.77 Domain Names -> http://domains.us-webmasters.com/


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

Date: Thu, 13 May 2004 23:55:58 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: RegEx to delete // comments NOT in quotes: ( ' ) OR (")???
Message-Id: <TdGdnQKVbpThwjndRVn-jg@adelphia.com>

W. D. wrote:
> ===================== Code Start ==========================
> // Some comments that should be trashed
> 
> Code goes here;
> 
> $SomeVar = '// These comments should be left alone!';
> 
> /* Some more comments that will remain */
> 
> " // These comments should also be left alone "
> 
> # Hash/Pound sign comments should remain for now
> 
> More Code goes here
> 
>        { This code should stay // This comment should go
>        }
> =========================== Code End ===========================
> 
> Does anyone know how to create a RegEx to do this????!
> 

Derived from perlfaq on regex:

#!/usr/bin/perl

  my $lines = <<ENDTEXT;
     // Some comments that should be trashed
     Code goes here;
     \$SomeVar = '// These comments should be left alone!';
     /* Some more comments that will remain */
     \" // These comments should also be left alone \"
     # Hash/Pound sign comments should remain for now
     More Code goes here
     { This code should stay // This comment should go
        }
ENDTEXT

print $lines, "\n\n\n";

# this needs whitespace reformatting, but you're using PHP :{
$lines =~ 
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
print $lines, "\n";






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

Date: Thu, 13 May 2004 23:59:08 -0400
From: "Mike Lepore" <lepor5e@bestweb.net>
Subject: Rounding a Number
Message-Id: <10a8gv2omh3ppba@corp.supernews.com>

How can I round a number to the nearest n decimal places?
I know the basic algorithm is to multiply by 10 to the power n,
add 0.5, floor it (drop the digits after the decimal point,
and keep the integer), and then divide by 10 to the power n.
However, I don't know how to cut off the digits after the
decimal point.  Thanks.

--

Mike Lepore, email delete the 5





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

Date: Fri, 14 May 2004 04:01:32 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Rounding a Number
Message-Id: <x7oeorac84.fsf@mail.sysarch.com>

>>>>> "ML" == Mike Lepore <lepor5e@bestweb.net> writes:

  ML> How can I round a number to the nearest n decimal places?
  ML> I know the basic algorithm is to multiply by 10 to the power n,
  ML> add 0.5, floor it (drop the digits after the decimal point,
  ML> and keep the integer), and then divide by 10 to the power n.
  ML> However, I don't know how to cut off the digits after the
  ML> decimal point.  Thanks.

FAQ

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 14 May 2004 00:13:47 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Rounding a Number
Message-Id: <ub2dndYlopPm2jnd4p2dnA@adelphia.com>

Mike Lepore wrote:

> How can I round a number to the nearest n decimal places?

By using the method documented in 'perldoc perlfaq4', and easily found with
'perldoc -q round'.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Fri, 14 May 2004 04:18:41 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Rounding a Number
Message-Id: <slrnca8i51.6fl.dha@panix2.panix.com>

In article <10a8gv2omh3ppba@corp.supernews.com>, Mike Lepore wrote:
> How can I round a number to the nearest n decimal places?
> I know the basic algorithm is to multiply by 10 to the power n,
> add 0.5, floor it (drop the digits after the decimal point,
> and keep the integer), and then divide by 10 to the power n.
> However, I don't know how to cut off the digits after the
> decimal point.  Thanks.

Perhaps a look at 

	perldoc -q round

might be of help.

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
You get the idea that if Apple won a 90% market share, bought out
Microsoft, and hired Bill Gates to mop the bathrooms, Business Week
would write: "Apple has all but ignored the possibility of alien
invasion..."	- David Pogue


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

Date: Fri, 14 May 2004 14:47:30 +1000
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: Rounding a Number
Message-Id: <bigiain-34993E.14473014052004@individual.net>

In article <10a8gv2omh3ppba@corp.supernews.com>,
 "Mike Lepore" <lepor5e@bestweb.net> wrote:

> How can I round a number to the nearest n decimal places?
> I know the basic algorithm is to multiply by 10 to the power n,
> add 0.5, floor it (drop the digits after the decimal point,
> and keep the integer), and then divide by 10 to the power n.
> However, I don't know how to cut off the digits after the
> decimal point.  Thanks.


You ask the faq!

perldoc -q round

will reveal what you seek?

(here's a hint, its all about sprintf...)

cheers,

big
-- 
'You know all those spasticated-looking hip-hop gestures involving
extended fingers and wrists cocked at odd angles which are intended to 
have a meaning to the effect of "Kinoath!" or "You have spoken wisely,
my friend."? I'm making one in your direction now...' Marko in aus.moto


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

Date: Fri, 14 May 2004 10:27:37 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: Stopping code execution in RE's
Message-Id: <c813pp$7fh$1@bunyip.cc.uq.edu.au>

Anno Siegel wrote:

> In full generality, "eval" will be hard to avoid, but you *can* reduce
> its use to the extraction of variable values.  Something like this
> 
>     for my $varname ( $regex =~ /(\$[A-Za-z_]\w*)/g ) {
>         my $val = eval "qq($varname)";
>         $varname = '\\' . $varname;
>         $regex =~ s/$varname/$val/g;
>     }
>     my $re = qr/$regex/;

On parsing the file my RE object consists of a list of strings and variable 
names. The variable names are resolved before the perl-RE is built from the RE 
object and wrapped in \Q/\E so I don't have to worry about weird values....

> I'm wondering how the user knows what variables they can use.  If they
> are user-defined variables, the user can do their own interpolation,
> so I assume the variables are defined in your program.  But then
> the user needs some kind of catalog of what variables are available.
> 
> In that case you could build a hash of all possible variable names
> and their (string) values and substitute according to that.  No
> eval is needed.

The 'language' allows specification of variables (scalars like $FOO, arrays like 
@FOO and array elements like @FOO[INDEX]) that are stored in a hash-structure 
inside a Storage package. Once again, the stumbling block is the special quote 
characters \Q, \L, \U, \l, \u and \E - I'm having a hard time building a valid 
RE out of, say:

$part1 = '\QThis is quoted';
$part2 = '\Uthis is uppercase';

because:

$re = qr/$part1$part2/;
$re2 = qr/\QThis is quoted\Uthis is uppercase/;
$re3 = eval "qr/$part1$part2/";
print "RE1 IS $re\nRE2 IS $re2\nRE3 IS $re3\n";

results in:

RE1 IS (?-xism:\QThis is quoted\Uthis is uppercase)
RE2 IS (?-xism:This\ is\ quotedTHIS\ IS\ UPPERCASE)
RE3 IS (?-xism:This\ is\ quotedTHIS\ IS\ UPPERCASE)

I'm currently reworking it so that when the parser finds an RE (or an 
interpolated string), instead of building a list of strings and variable names, 
it builds a list of strings, variable names and inline commands so that by the 
time the real RE is built the strings/variable values have been 
quoted/uppercased/lowercased etc so I don't need the eval.

Who would've thought that building a language was so complex :)

MB



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

Date: Fri, 14 May 2004 03:07:40 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Stopping code execution in RE's
Message-Id: <c81d5s$gvo$1@wisteria.csv.warwick.ac.uk>


Quoth Matthew Braid <mb@uq.net.au.invalid>:
> The 'language' allows specification of variables (scalars like $FOO, arrays like 
> @FOO and array elements like @FOO[INDEX]) that are stored in a hash-structure 
> inside a Storage package. Once again, the stumbling block is the special quote 
> characters \Q, \L, \U, \l, \u and \E - I'm having a hard time building a valid 
> RE out of, say:
> 
> $part1 = '\QThis is quoted';
> $part2 = '\Uthis is uppercase';
> 
> because:
> 
> $re = qr/$part1$part2/;
> $re2 = qr/\QThis is quoted\Uthis is uppercase/;
> $re3 = eval "qr/$part1$part2/";
> print "RE1 IS $re\nRE2 IS $re2\nRE3 IS $re3\n";
> 
> results in:
> 
> RE1 IS (?-xism:\QThis is quoted\Uthis is uppercase)
> RE2 IS (?-xism:This\ is\ quotedTHIS\ IS\ UPPERCASE)
> RE3 IS (?-xism:This\ is\ quotedTHIS\ IS\ UPPERCASE)

How about

$part1 = '\QThis is quoted';
$part2 = '\UThis is uppercase';

for ($part1, $part2) {
    s!/!\\/!g;
    $_ = eval "qr/$_/";
}

$re = qr/$part1$part2/;
print $re;

(?-xism:(?-xism:This\ is\ quoted)(?-xism:THIS IS UPPERCASE))

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Fri, 14 May 2004 01:54:10 +0000 (UTC)
From: Irving Kimura <nomail_please@nomail.org>
Subject: Re: Why Carp::croak over die?
Message-Id: <c818s2$ses$1@reader2.panix.com>

In <c801po$i2i$1@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
>When I'm writing modules, I use carp/croak for things which are the
>user's fault, and warn/die for things which are my fault (obviously,
>such things never happen :).

That's very helpful.  Thanks,

Irv

-- 


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V10 Issue 6561
***************************************


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