in reply to rebuilding a hash (more)

Besides the fact, that your code is quite complicated, you have this in it:
foreach (sort keys %upload)
sort will sort alphabetically giving you (example):
0 1 10 100 101 11 : 19 2 20 :
If you use numbers as indices, you should use an array!

otherwise try sort { $a<=>$b } keys %upload

Replies are listed 'Best First'.
Re: Re: rebuilding a hash (more)
by davido (Cardinal) on Feb 20, 2004 at 06:55 UTC
    If you use numbers as indices, you should use an array!

    Not necessarily. It makes no sense to use an array if the indices of its only elements are 2, 24, and 35000. For sparse arrays, hashes are a good choice.

    As for his sort problem, there are ways around it by using a smarter sort function.


    Dave

      > Not necessarily.

      Agreed. But as he said, he don't want to have a gap, and his code is (at least) trying to close gaps, arrays would be, to my understanding, the best choice here.
Re: Re: rebuilding a hash (more)
by coldfingertips (Pilgrim) on Feb 20, 2004 at 07:16 UTC
    I replaced it with the correct sort, I overlooked that. But does anyone know why I it appears I can delete images correctly but when I try to delete the newest one it deletes a few images?