Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 903703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:55:45+00:00 2026-05-15T15:55:45+00:00

I have this piece of script : #!/usr/bin/perl use strict; use warnings; use Data::Dumper;

  • 0

I have this piece of script :

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

my @arr = (
    {
        name  => 'foo',
        value => 123,
    },
    {
        name  => 'bar',
        value => 'nan',
    },
    {
        name  => 'foobar',
        value => 456,
    },
);

@arr = sort {$a->{value} <=> $b->{value} } @arr;

print Dumper(\@arr);

I don’t have any problems under Windows XP / Strawberry Perl 5.10.1

either Linux 2.6.12-1 i386 / Perl v5.8.5 built for i386-linux-thread-multi,

but under Linux 2.6.18-53 / Perl v5.8.8 built for x86_64-linux-thread-multi, i got the error message :

Sort subroutine didn't return a numeric value at testsort.pl line 21.

What’s going wrong and how can i fix it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:55:46+00:00Added an answer on May 15, 2026 at 3:55 pm

    In some builds, ‘nan’ is coerced to the number 0 for a <=> comparison and the sort succeeds. In other builds, nan is treated as “not a number” and the return value from <=> is undefined.

    For maximum portability, test a value for whether it is a good number of not:

    (isnan subroutine from How do I create or test for NaN or infinity in Perl?):

    sub isnan { ! defined( $_[0] <=> 9**9**9 ) }
    
    @arr = sort { isnan($a->{value}) ? 0 : $a->{value}
                             <=>  
                  isnan($b->{value}) ? 0 : $b->{value} }  @arr;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working perl script that grabs the data I need and displays
I have this piece of simple code. <html> <head> <script type=text/javascript> function changeText() {
In javascript suppose you have this piece of code: <div> <script type=text/javascript>var output =
Hey guys, I have this piece of jquery code: <script type=text/javascript > $(function() {
I have this little piece of code: <script> $(window).bind('beforeunload', function() { $.ajax({ async: false,
I have been using this piece of script to load external .js files to
I have this piece of javascript: <script type=text/javascript> function show_confirm() { var type =
I have this piece of code: <script language=javascript type=text/jscript> document.write(<img src='http://dm.leadgenesys.com/jpgp.lgt?en=P.........TP_Q=&amp;ur=' + escape(document.referrer) +
I have this script piece in an javascript function to validate some fields in
I have this piece of code written in jQuery and PHP: <script type=text/javascript> $(document).ready(function(){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.