How to find if a key exist in hash?

2004-09-29 Thread Edward Wijaya
Hi, I have the following code, and I know it is HORRIBLE. I wonder if I can do it in more efficient and elegant way? Thanks so much and Regards, Edward WIJAYA SINGAPORE __BEGIN__ use strict; use warnings; use Getopt::Std; use Data::Dumper; my %hash = ( A => 'blabla', B => 'dadada',

Re: How to find if a key exist in hash?

2004-09-29 Thread Gunnar Hjalmarsson
Edward Wijaya wrote: Subject: How to find if a key exist in hash? There is a builtin Perl function for the purpose. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <h

RE: How to find if a key exist in hash?

2004-09-29 Thread NYIMI Jose \(BMB\)
> -Original Message- > From: Edward Wijaya [mailto:[EMAIL PROTECTED] > Sent: Wednesday, September 29, 2004 12:17 PM > To: [EMAIL PROTECTED] > Subject: How to find if a key exist in hash? > > > Hi, > > I have the following code, > and I know it is HO

Re: How to find if a key exist in hash?

2004-09-29 Thread max4o
%a = ( "a" => 1, "b" => 2, "c" => 3 ); $searchKey = "a"; print "Found $searchKey" if defined($a{$searchKey}); - This mail is from: <[EMAIL PROTECTED]> - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additiona

Re: How to find if a key exist in hash?

2004-09-29 Thread John W. Krahn
[EMAIL PROTECTED] wrote: %a = ( "a" => 1, "b" => 2, "c" => 3 ); $searchKey = "a"; print "Found $searchKey" if defined($a{$searchKey}); Try that with this hash: my %a = ( a => undef, b => undef, c => undef, ); defined() does not tell you if a key exists. perldoc -f exists Jo