develooper Front page | perl.perl5.porters | Postings from December 2013

Re: [perl #118237] Re: [perl #120752] t/op/coreamp.t fails with verysmall random numbers

From:
Dabrien 'Dabe' Murphy
Date:
December 15, 2013 06:37
Subject:
Re: [perl #118237] Re: [perl #120752] t/op/coreamp.t fails with verysmall random numbers
Message ID:
52AB57C0.5040502@dabe.com
On 12/13/13, 5:46 AM, Zefram via RT wrote:
> All this regexp business is entertaining, and I'm not one to shy away
> from solving a problem with a regexp, but in this case it's firmly the
> wrong tool for the job.

You're right, of course...  Not that the test code does it, but I wasn't 
even thinking about what would happen in a locale that uses "," as the 
decimal separator.

> How about a numeric comparison?
>
> 	my $r =&CORE::rand;
> 	ok $r>= 0&&  $r<  1;

My only issue there is that, as written, the empty string and 
non-numeric text output (like, "ERROR: Frobnication Failure") would 
still pass.

How 'bout:

     my $r = &CORE::rand;
     ok eval {
         use warnings FATAL => qw{numeric uninitialized};
         $r >= 0 && $r < 1;
     }, '&rand returns a valid number';

?

-- 
:- Dabe





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About