Re: How to check empty hash value properly?
- From: shawnhcorey@xxxxxxxx (Mr. Shawn H. Corey)
- Date: Mon, 06 Oct 2008 10:16:22 -0400
On Mon, 2008-10-06 at 22:35 +0900, Raymond Wan wrote:
Try:
if (defined $hash{$key}) {
...
Defined is not the same as exists.
#!/usr/bin/perl
use strict;
use warnings;
my %data = (
b => undef,
c => 1,
);
for my $key ( qw( a b c ) ){
print "\$key = $key\n";
if( exists $data{$key} ){
print "\t\$data{$key} exists\n";
if( defined $data{$key} ){
print "\t\$data{$key} defined\n";
print "\t\$data{$key} = $data{$key}\n";
}else{
print "\t\$data{$key} not defined\n";
}
}else{
print "\t\$data{$key} not exists\n";
}
print "\n";
}
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
Linux is obsolete.
-- Andrew Tanenbaum
.
- Follow-Ups:
- Re: How to check empty hash value properly?
- From: Loody
- Re: How to check empty hash value properly?
- References:
- How to check empty hash value properly?
- From: Loody
- Re: How to check empty hash value properly?
- From: Raymond Wan
- How to check empty hash value properly?
- Prev by Date: Re: combinations
- Next by Date: Re: how can i untain $ARGV from a perl script extending snmp? [solved]
- Previous by thread: Re: How to check empty hash value properly?
- Next by thread: Re: How to check empty hash value properly?
- Index(es):
Relevant Pages
|