Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: comparing two array

by Crian (Chaplain)
on Jun 17, 2009 at 12:37 UTC ( #772373=note: print w/replies, xml ) Need Help??

in reply to Re: comparing two array
in thread comparing two array

Shouldn't it be

print exists $h{$elem} ? "Yes" : "No";
the second example?

Replies are listed 'Best First'.
Re^3: comparing two array
by JavaFan (Canon) on Jun 17, 2009 at 12:42 UTC
    Considering all the values in %h are 1, it doesn't make any difference whether you use exists $h{$elem}, defined $h{$elem} or $h{$elem}.
Re^3: comparing two array
by citromatik (Curate) on Jun 17, 2009 at 12:54 UTC

    In this case...

    print defined $h{$elem} ? "Yes" : "No"; print exists $h{$elem} ? "Yes" : "No"; print $h{$elem} ? "Yes" : "No";

    Are all equivalent (give the same result). exists returns true if the specified element in the hash has ever been initialized, even if its current value is undefined. In this case, all elements has been initialized to 1. If you undefine one element of the hash, for example undef $h{$elem}, then $h{$elem} still exists, but its value is undef


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://772373]
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2017-05-29 00:36 GMT
Find Nodes?
    Voting Booth?