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',
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
> -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
%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
[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