loody wrote:
>>  if( exists $data{$key} ){
>>    print "\t\$data{$key} exists\n";
>
> thanks for your kind help.
> Could I get the conclusion that exists is only used for determining
> the element of hash and arrays?
> appreciate your help,

Consider this program.

  use strict;
  use warnings;

  my @array;
  $array[0] = 'a';
  $array[2] = undef;

  my %hash;
  $hash{a} = 1;
  $hash{c} = undef;

Now,

exists $array[1] and exists $hash{b} will be false.

exists $array[2] and exists $hash{c} will be true.

defined $array[1], defined $array[2], defined $hash{b}, and defined $hash{c}
will all be false.

So an array or hash element may exist but have an undefined value. defined()
will return true only if the elements exists and has a defined value. exists()
will return true if the element exists, regardless of its value.

Note also that undef $array[0] and undef $hash{a} leave the element in existence
but make its value undefined, while delete $array[0] and delete $hash{a} make
the element non-existent.

HTH,

Rob






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to