On Tue, Nov 20, 2001 at 12:41:03PM -0800, Ahmed Moustafa Ibrahim Ahmed wrote:
> If I know the key and offset of the element, how can I delete that hash
> element, please?

As far as I understand the followup clarification, what you really want to
do is delete an element in an array, which just happens to be in a hash.

So, you have a data structure something like:

    %hash = (
        key1    =>  ['key1, element1', 'key1, element 2'],
        key2    =>  ['key2, element1', 'key2, element2', 'key2, element3'],
    );

And you want to delete the first element in the $hash{'key2'} array.  That'd
be accomplished like so:

    unshift @{ $hash{'key2'} };

Or, say you want to delete the second element in the $hash{'key1'} array:

    splice(@{ $hash{'key1'} }, 1, 1)


See perldoc perldata for more information on dealing with arrays, perldoc
perldsc for information on dealing with complex data structures, and perldoc
-f unshift and perldoc -f splice for information on the unshift and splice,
respectively.


I'm really surprised at some of the people suggesting you use delete for
this.  Most of them should know better.  Using delete on an array element
will remove that element, but only if it's on the end.  If it's in the
middle, or at the beginning of the array, it'll simply cause the exists
operator to return false for that element.  I doubt that's what you wanted.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to