On 4/4/06, Lawrence Statton <[EMAIL PROTECTED]> wrote:
> > 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 ); s
perl wrote:
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
Thank you
print keys(%some_hash) == 1
> 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 =>
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 ? pri
some_hash == 1 ? print "true" : print "false"'
false
Is it useful for you?
-Original Message-
>From: perl <[EMAIL PROTECTED]>
>Sent: Apr 5, 2006 9:26 AM
>To: beginners@perl.org
>Subject: only one of two hash keys
>
>Is there a nice clean perl way to
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
Thank you
--
To unsubscribe, e-mail: [EMAIL PROTECTED]