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? -----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 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] >For additional commands, e-mail: [EMAIL PROTECTED] ><http://learn.perl.org/> <http://learn.perl.org/first-response> > > -- Jeff Pang NetEase AntiSpam Team http://corp.netease.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>