> i want to remove items from a hash then later see if they exist using
> defined(). for example:
>
You don't see if they exist using 'defined', you see if they are defined
:-). To see if they exist, you use 'exists'. Which hits to the heart of
your questions below.
> delete($hash{MYKEY});
This removes the spot in the hash for that value, which does make it not
defined.
> # blah blah
> if (defined($hash{MYKEY})) {
> # do blah blah
> }
In most cases this is sufficient.
>
> which should i use? delete() or undef()? obviously i could write a small
> script to test this (which i'm going to know), but i'd also like to hear
> from an expert about the subtle (if any) difference between the two if
they
> both work.
>
Not sure that I qualify as an expert, but there is a difference. using
'undef' will set the value to a particular key in the hash to the
undefined value, where 'delete' will remove that key/value pair from the
hash completely. In the case of setting the value to undef, 'defined'
will fail, but 'exists' will still be true; when doing 'delete' both
will fail.
perldoc -f undef
perldoc -f exists
perldoc -f delete
> also, are these functionally equivalent?
> $myvar = undef();
> undef($myvar);
>
To my knowledge.
HTH,
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>