On Wed, 2006-04-05 at 09:35 +0800, Jeff Pang wrote:
> Hello,
> 
> [EMAIL PROTECTED] ~/app]$ perl -le '%some_hash=(aa=>'bb');scalar keys 
> %some_hash == 1 ? print "true" : print "false"'
> true
> [EMAIL PROTECTED] ~/app]$ perl -le '%some_hash=(aa=>'bb',cc=>'dd');scalar 
> keys %some_hash == 1 ? print "true" : print "false"'
> false
> 
> Is it useful for you?
Thank you for the quick response.

That is a nice solution to the problem I stated.

But I should have said ... 

Is there a nice clean perl way to test to see if only one key of a hash
has data?

%some_hash = ( key1 => 1, key2 => 2 ); should fail the test
%some_hash = ( key2 => 2 ); should pass the test
%some_hash = ( key1 => 1 ); should pass the test
%some_hash = ( key1 => 1, key2 => 2, key3 => 3 ); should fail the test
%some_hash = ( key2 => 2 ); should pass the test
%some_hash = ( key1 => 1 ); should pass the test
%some_hash = ( key2 => 2, key3 => 3 ); should pass the test
%some_hash = ( key1 => 1, key3 => 3 ); should pass the test

Basically I can many more keys in the hash but two of the keys have to
be exclusive.

Thanks

> >Thank you
> >
> >
> >-- 


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


Reply via email to