Re: test for real number

2001-06-01 Thread Paul
--- Piers Cawley <[EMAIL PROTECTED]> wrote: > Paul <[EMAIL PROTECTED]> writes: > > BTW, this is another use of the same sort of trick as > > > > { local $/ = undef; > > $file = ; # slurp the whole file into $file > > } > > > > which is more efficient than > > > >while() { $file .=

Re: test for real number

2001-05-31 Thread Piers Cawley
Paul <[EMAIL PROTECTED]> writes: > BTW, this is another use of the same sort of trick as > > { local $/ = undef; > $file = ; # slurp the whole file into $file > } > > which is more efficient than > >while() { $file .= $_ } > > or > >$file = join '', ; > > Still, I have a co

Re: test for real number

2001-05-31 Thread Paul
List, I got this paragraph in recent correspondence with someone off-list: > I'm not so much discouraged as realize that I need a bit more time > with Perl before I can understand most of what gets passed around in > the list. I'll be back in a couple of months. From my short exposure, > it seem

Re: advanced: closures (was Re: test for real number)

2001-05-31 Thread Peter Scott
At 10:51 AM 5/31/01 -0700, Randal L. Schwartz wrote: >There's a school of (mis-)thought that "a coderef is a closure". I >don't know how that got started, but it's wrong. A closure is created >only when lexical variables go out of scope. So a coderef without >external references is *not* a clos

Re: advanced: closures (was Re: test for real number)

2001-05-31 Thread Randal L. Schwartz
> "Jeff" == Jeff Pinyan <[EMAIL PROTECTED]> writes: Jeff> I was scolded highly about that by Uri, back when my article[1] about Jeff> closures. I, too, felt that foo() should be called a closure, but Uri Jeff> seemed so convincing. If you're going to let me say that functions that Jeff> ref

Re: advanced: closures (was Re: test for real number)

2001-05-31 Thread Jeff Pinyan
On May 31, Randal L. Schwartz said: >> "Jeff" == Jeff Pinyan <[EMAIL PROTECTED]> writes: > >Jeff> A closure is an ANONYMOUS function (constructed via $x = sub { >Jeff> ... }) that contains LEXICAL variables that have been defined in >Jeff> a scope visible to the closure itself. > >leave out t

Re: advanced: closures (was Re: test for real number)

2001-05-31 Thread Randal L. Schwartz
> "Randal" == Randal L Schwartz <[EMAIL PROTECTED]> writes: > "Jeff" == Jeff Pinyan <[EMAIL PROTECTED]> writes: Jeff> A closure is an ANONYMOUS function (constructed via $x = sub { Jeff> ... }) that contains LEXICAL variables that have been defined in Jeff> a scope visible to the closure

Re: advanced: closures (was Re: test for real number)

2001-05-31 Thread Randal L. Schwartz
> "Jeff" == Jeff Pinyan <[EMAIL PROTECTED]> writes: Jeff> A closure is an ANONYMOUS function (constructed via $x = sub { Jeff> ... }) that contains LEXICAL variables that have been defined in Jeff> a scope visible to the closure itself. leave out the word ANONYMOUS there. ANONYMOUS and CLOS

advanced: closures (was Re: test for real number)

2001-05-31 Thread Jeff Pinyan
On May 31, Randal L. Schwartz said: >Paul> Be careful with this, though -- if you call some other function >Paul> from this scope, the value of $SIG{__WARN__} will still be the >Paul> routine that increments $bad, but it won't be able to see the >Paul> $bad we made with my()! > >Wrong. It'll sti

Re: test for real number

2001-05-31 Thread Paul
--- "Randal L. Schwartz" <[EMAIL PROTECTED]> wrote: > > "Paul" == Paul <[EMAIL PROTECTED]> writes: > > Paul> This is lovely, and a great opportunity to show some new toys > Paul> to beginners, as well as some well-placed caveats. With your > Paul> indulgence, I'll try to break this down for

Re: test for real number

2001-05-31 Thread Randal L. Schwartz
> "Paul" == Paul <[EMAIL PROTECTED]> writes: Paul> This is lovely, and a great opportunity to show some new toys to Paul> beginners, as well as some well-placed caveats. With your indulgence, Paul> I'll try to break this down for the newbies. :) Great! Paul> Be careful with this, though --

Re: test for real number

2001-05-31 Thread Paul
--- "Randal L. Schwartz" <[EMAIL PROTECTED]> wrote: > > The most comprehensive test for a real number is to let Perl > do it itself: > > sub is_number { > my $bad = 0; > local $SIG{__WARN__} = sub { $bad++ }; > local $^W = 1; > my $guess = shift; > $guess += 0;

Re: test for real number

2001-05-31 Thread Randal L. Schwartz
> "Timothy" == Timothy Kimball <[EMAIL PROTECTED]> writes: Timothy> Randal L. Schwartz wrote Timothy> : For integers, you can narrow it down: Timothy> : Timothy> : sub is_integer { Timothy> : my $bad = 0; Timothy> : local $SIG{__WARN__} = sub { $bad++ }; Timothy> : loca

Re: test for real number

2001-05-31 Thread Timothy Kimball
Randal L. Schwartz wrote : For integers, you can narrow it down: : : sub is_integer { : my $bad = 0; : local $SIG{__WARN__} = sub { $bad++ }; : local $^W = 1; : my $guess = shift; : return $guess == int($guess) and not $bad; : } oops, precedence: return $g

Re: test for real number

2001-05-31 Thread Randal L. Schwartz
The most comprehensive test for a real number is to let Perl do it itself: sub is_number { my $bad = 0; local $SIG{__WARN__} = sub { $bad++ }; local $^W = 1; my $guess = shift; $guess += 0; return not $bad; } If adding 0 didn't trigger the numeric war

Re: test for real number

2001-05-30 Thread Morten Sickel
Hi Mike, You wrote: >How do I test an input to see if it is a real number? I have a situation >something like: (slightly snipped) >if (input equals a real number) { >xx >} >else { > >} Do you mean 'if it really is a number' or 'a real number' in the matematical sense? If you

Re: test for real number

2001-05-30 Thread Carl Rogers
Good day; try::: if ($input =~ /\d+\.?\d+/){ xxx } The intent here is: \d+ ##one or more digits \.? ##followed by zero or one "." (there is a dot there) \d+ ##followed by one or more digits. I think this will work. Depending on how your reals will be input, you c

Re: test for real number

2001-05-30 Thread Jeff Pinyan
On May 30, [EMAIL PROTECTED] said: >I'm new to the group and new to Perl and am very glad to have such a >resource available. Hopefully someday I'll be on the giving end of the >help list but for now I'm stumped. How do I test an input to see if it >is a real number? I have a situation someth

Re: test for real number

2001-05-30 Thread Paul
--- [EMAIL PROTECTED] wrote: > help list but for now I'm stumped. How do I test an input to see if > it is a real number? I have a situation something like: By "real number", exactly what do you mean? Do you mean a decimal fraction without characters other than 0123456789.+- or do you want to i

Re: test for real number

2001-05-30 Thread Walt Mankowski
On Wed, May 30, 2001 at 01:56:40PM -0700, [EMAIL PROTECTED] wrote: > How do I test an input to see if it is a real number? $ perldoc -q float Found in /usr/local/lib/perl5/5.6.1/pod/perlfaq4.pod How do I determine whether a scalar is a number/whole/integer/float? Assuming that y

test for real number

2001-05-30 Thread mikemckee
Hi, I'm new to the group and new to Perl and am very glad to have such a resource available. Hopefully someday I'll be on the giving end of the help list but for now I'm stumped. How do I test an input to see if it is a real number? I have a situation something like: $input = ; chom