-----BEGIN PGP SIGNED MESSAGE-----

On Wed, 27 Oct 1999, Jean-Yves BARBIER wrote:

> My first table contains <long files names> <size in byte>
> As it comes without ordering on sizes, I want to sort it
> in another hash table, so I make:
> @New_Table = sort { $File_Table{$a} cmp $File_Table{b} } keys %File_Table;
> 
> but when I print both tables on the screen, New_Table is empty, why ??!
> (I took it from a book, and also test it with '<=>' instead of 'cmp',
>  but I'm still stuck)

Since you're sorting on size, <=> would be the proper operator, since you
want numeric comparisons on the file sizes.

Except for the typo in that $File_Table{b} should be $File_Table{$b}, it
works fine when i plug it into a test program.

Some things to try: run it with the -w option and watch for warnings. Make
sure you're printing @New_Table, and not %New_Table (note that trying to
store a sorted hash into %New_Table wouldn't work, because perl hashes
don't maintain the order of the data). If nothing else, send me the code
off the list and i'll see if i can help you.


- -- 
  finger for PGP public key.

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQCVAwUBOBd5/b7M/9WKZLW5AQGcsAP8DFRhQCot5j/OmC1+9756EJWtZpb49JV4
ujbFjtAV5zEy7ufKO6zpR3Wz7Wgz9l0SWygZmK5/gHJ3DkuNYUuIErQ1LGInAZX3
EZWwVmrp1MrM0dk1uY8/Q6u5LG8r9xYo3JHV3YAp1lBI+zDw01crbn6X/c+ZCFJa
M1QIYQRsaiQ=
=yIOB
-----END PGP SIGNATURE-----

Reply via email to