myocom has asked for the wisdom of the Perl Monks concerning the following question:
I'm sure this is straightforward enough, but for some reason I can't wrap my brain around an elegant solution. I have a hash that has keys of (100, 101, 102, 103, 104, 105, 106, 107). I'd like to remove some number of elements starting with some other arbitrary element. For example, 3 elements, starting with the 2nd (101, 102, 103). This is easy enough to compute with an array, since they're indexed on number, but I'm not sure how to do it with a hash.
The ugly way would be to create a parallel array that has the sorted keys of the hash, then foreach over a slice of that array and delete the appropriate hash elements. But surely there's a more elegant way, yes?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing a certain number of hash keys
by dws (Chancellor) on Dec 12, 2000 at 02:37 UTC | |
by myocom (Deacon) on Dec 12, 2000 at 02:43 UTC | |
by tye (Sage) on Dec 12, 2000 at 02:48 UTC | |
by Hot Pastrami (Monk) on Dec 12, 2000 at 03:00 UTC | |
|
(jeffa) Re: Removing a certain number of hash keys
by jeffa (Bishop) on Dec 12, 2000 at 02:33 UTC | |
|
Re: Removing a certain number of hash keys
by eg (Friar) on Dec 12, 2000 at 02:34 UTC | |
|
Re: Removing a certain number of hash keys
by cwest (Friar) on Dec 12, 2000 at 02:45 UTC | |
|
Re: Removing a certain number of hash keys
by Hot Pastrami (Monk) on Dec 12, 2000 at 02:38 UTC |