in reply to sorting exponential values in perl

From: perlnum:

Perl can internally represent numbers in 3 different ways: as native integers, as native floating point numbers, and as decimal strings. Decimal strings may have an exponential notation part, as in "12.34e-56" . Native here means "a format supported by the C compiler which was used to build perl".

If the number is represented in a format supported by the C compiler used to build Perl, it can be treated as a number, which is to say, you can sort it numerically using the numerical comparison operator, <=> (See perlop for an explanation of the flying-saucer operator. ;) ).

I would only question "e-133" as its status as a number. Is that 0e-133? That's still zero, but being that it starts as a non-numeric character, Perl might treat it as a string. If there is any question as to what Perl sees as a number, you can always use the Scalar::Util module's "looks_like_number()" function to determine what Perl thinks it is.

Of course there is the convenience with Perl that any string can be treated like a number. If it doesn't make sense as a number, it just evaluates to zero, which may or may not be what you want, but at least is "defined behavior."


Dave