According to the perlfunc manpage on sort, I should be able to use <=> to compare things, and if it's NaN, it turns out undefined. I think the page is outdated. The following turns out true in ActiveState Perl Build 810 (Perl 5.8.4):
$a = 'string';
if (defined ($a <=> $a)) { print "Oops"; }
The == operator also seems to work for NaNs (Not-a-Numbers) when it's not supposed to.
I think you are under a misapprehension. $a there is not a NaN; a NaN is a floating point value that doesn't correspond to an actual number. On systems that support NaNs and infinite numbers, there are various rules about when a math operation will return one of these types. Try:
my $Inf = 9**9**9;
my $NaN = sin($Inf);
print "inf is: $Inf\n", "NaN is: $NaN\n";
Note: these are not strings; setting $a = "Inf" is not
the same as setting it to an Inf floating point value.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|