Forum Moderators: coopster & phranque

Message Too Old, No Replies

Undefining an element of an array of hashes.

Wont work !?

         

physics

9:16 pm on Dec 13, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have an array such as:
@myarray;
Then, each element of the array is a hash, thus:
$myarray[1]{'foo'}="foo1";
$myarray[1]{'bar'}="bar1";
$myarray[2]{'foo'}="foo2";
$myarray[2]{'bar'}="bar2";
And so on.
Later I go through and do some stuff to each element at a time. I'd like to undef all of the key value pairs of $myarray[1] after I use them, but I can't seem to do it. I've tried
undef $myarray[1]{'foo'};
but it won't work ... any ideas?

amoore

9:57 pm on Dec 13, 2001 (gmt 0)

10+ Year Member



Short answer:
use "delete" instead of "undef"

long answer:
You have an array of hashes there. In one hash you have set the value that one of your keys refers to to "undef". This means the hash still has that entry, but it the value held in it is "undef". More info is in perlfaq #4 at:
[perldoc.com...]

physics

10:33 pm on Dec 13, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks!