in reply to modifying the key of hash of arrays

Keys themselves are immutable. However, you can assign the value held in a hash element to a new key and delete the old one.

"I am trying:

$b="blah"; $hasharr{$rephead}=$b; #but i think i am accessing the array rather than the key.

Yes, you are writing "blah" into the value of the hash key/value pair, overwriting the anonymous array you had stored there.

Here is what you need to do:

$hasharr{$newkey} = $hasharr{$rephead}; delete $hasharr{$rephead};


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Replies are listed 'Best First'.
Re: Re: modifying the key of hash of arrays
by hardburn (Abbot) on Oct 16, 2003 at 13:41 UTC

    delete returns the value of the key it deleted, so you actually only need:

    $hasharr{$newkey} = delete $hasharr{$rephead};

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    :(){ :|:&};:

    Note: All code is untested, unless otherwise stated