in reply to rebuilding a hash (more)

The sort keys not doing a numeric sort is definitely going to cause some unusual effects for you. The other very wrong thing I see is that second delete $upload{count}. I think that will cause you to delete an extra record when you are trying to delete the last one. Fix it by skipping the second loop (everything that involves $count) and just deleting $upload{++$num} after the first loop instead.

In terms of style points, you should be saying = -1, not = "-1"; there's no point in setting a string and then turning around and incrementing it; just use a number.

I assume you are using the split-up parts $filename2, etc. in code that you've trimmed away; if these are really unused, get rid of the split and join lines and just use $upload{$_} where you have $joined.

And I'd say $upload{$num} = $joined if $num != $_; no point in updating your database if nothing changed.

Replies are listed 'Best First'.
Re: Re: rebuilding a hash (more)
by coldfingertips (Pilgrim) on Feb 20, 2004 at 10:26 UTC
    Thank you so much!! It now rebuilds the hash without gaps and I can delete the first, last or middle images and have it work perfectly. Though I don't see why removing the second foreach did the trick (I only deleted one time), but it works like a charm.

    Thanks for all your help!

      The second foreach would always delete the last thing in the hash (where last thing means after the first delete). This works where you've moved everything up to close up a gap, since the last entry would be an invalid one then. It doesn't work where you've deleted the last entry; it goes ahead and deletes what was originally the second to last entry.

      Try writing down on paper what happens at each step, with keys 1, 2, and 3 and deleting key 3.