in reply to Hashing: Argument "" isn't numeric in sort

The <=> operator only works in numeric context. You need the cmp operator instead, which works in string context:

foreach $keyOut (sort {$a cmp $b} keys %hshOut) { ... }

Alternative: use Data::Dumper to dump your hash (assuming you're doing this for debugging purposes and not dumping it for user-viewable data).

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Hashing: Argument "" isn't numeric in sort
by P0w3rK!d (Pilgrim) on May 20, 2003 at 14:56 UTC
    The keys look something like 465.274. The keys used to be numeric and then they became strings. Thanks for catching this for me.
    -P0w3rK!d
      It's quite impossible to change a hash-key, they are constant strings - strictly speaking they cannot even be numbers.

      The string "465.274" is converted to a number when needed by perl, so that should not give you this warning, as the following code shows:

      #!/usr/bin/perl -wl use strict; my @array = qw(465.274 21893.32 72.37); # qw creates quoted strings print for (sort {$a <=> $b} @array);

      output:

      72.37 465.274 21893.32

      No warnings at all.

      Joost

      -- #!/usr/bin/perl -np BEGIN{@ARGV=$0}s(^([^=].*)|=)()s; =Just another perl hacker\