in reply to Determine largest key in hash
At any given level, keys (as in my $n = keys %{ $hashref };) will tell you how many elements exist at that level.
Which if the only keys in the hash were the numeric ones, then that would tell you what number to use for the next insertion. But in that case, you'd be far better off using an array rather than a hash.
But for the second level in your structure, where you have other, non-numeric keys, then that won't work. But then, if you added a key '2' at that level, where are you going to store the associated 'name' & 'that'? Because if you try to store them as you have the first set, you'll just overwrite them.
Bottom line is that you almost certainly need to review your data structure.
Perhaps if you outlined what the data was and where it came from, we might be able to help you with that.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Determine largest key in hash
by Anonymous Monk on Oct 04, 2011 at 17:48 UTC | |
by MidLifeXis (Monsignor) on Oct 04, 2011 at 17:56 UTC | |
by BrowserUk (Patriarch) on Oct 04, 2011 at 18:02 UTC |